3

I'm developing an android app in which I would like to save the data with GeoFire location and then fetch it according to the location.

The problem is that I'm not sure how to save the data along with GeoFire location, though I'm able to save it using .push().setValue() method.

I actually have no code as I'm clueless how to do what I want.

Please let me know.

Sorry, if question seems badly formatted. I'm still a beginner here.

Ziyaddin Sadigov
  • 8,893
  • 13
  • 34
  • 41
Hammad Nasir
  • 2,889
  • 7
  • 52
  • 133

1 Answers1

0
String key_of_data= ref.child("feeds").push(data).getKey();

Now the key_of_data variable contains the key of the feed data. So to save that data, the only option is to create a reference to this key with GeoFire. So key_of_data is given as the key for geoFire.

geoFire = new GeoFire(ref.child("user_location"));
geoFire.setLocation(key_of_data, new GeoLocation(lattitude, longitude));

This is how you save the data. For retrieving the data use the following code.

geoFire=newGeoFire(FirebaseDatabase.getInstance().getReference().child("users_location");
geoQuery = geoFire.queryAtLocation(geoLocation), 1);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
    //key is the key to the feed data.
}
};    

For more deatils, refer this Stack post HERE

Febin Mathew
  • 991
  • 1
  • 11
  • 20