I have a firebase database(realtime database) with more than 700 objects. Each one of them has latitude and longitude. I would like to know if there is some way to query them and show only those which are near to the device location. I've tried to understand geofire but I couldn't.
This is a example from one object in firebase:
and this is what i've been using to show all data:
ChildEventListener childEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
mDatabase = FirebaseDatabase.getInstance().getReference();
Log.d(TAG, "onChildAdded:" + dataSnapshot.getKey());
//Get firebase info for each gym
Gym gym=dataSnapshot.getValue(Gym.class);
gym.setGym_id(dataSnapshot.getKey());
//Set custom marker with firebase info
LatLng newLocation= new LatLng(Double.parseDouble(gym.getLatitude()),Double.parseDouble(gym.getLongitude()));
if (dataSnapshot.hasChild("raid")){
Marker marker= mMap.addMarker(new MarkerOptions()
.position(newLocation)
.title(gym.getName())
.snippet(gym.getUrl())
.icon(BitmapDescriptorFactory.fromBitmap(bMapRaid)));
marker.setTag(gym);
} else {
Marker marker= mMap.addMarker(new MarkerOptions()
.position(newLocation)
.title(gym.getName())
.snippet(gym.getUrl())
.icon(BitmapDescriptorFactory.fromBitmap(bMap)));
marker.setTag(gym);
}
}