1

I have an android application which fetches the nearby keys using GPS Location and GeoFire. There are around 15,000 keys in the firebase database. Loading the nearby keys from Android App takes around 20 seconds. Why is it so? Although Firebase Geofire official documentation states that

GeoFire selectively loads only the data near certain locations, keeping your applications light and responsive, even with extremely large datasets.

Geofire Github Page

shikhar bansal
  • 1,629
  • 2
  • 21
  • 43
  • 1
    Did you add an index to the database for the `g` property, as described [here](https://github.com/firebase/geofire-java#upgrading-from-geofire-10x-to-11x) and shown in this [sample](https://github.com/firebase/geofire-js/blob/master/examples/securityRules/rules.json)? – Frank van Puffelen May 06 '17 at 14:17

3 Answers3

3

Thanks for the answers.

I solved my problem by making an Index on g (geohash) by putting ".indexOn": ["g"] in security rules of the Firebase Database.

shikhar bansal
  • 1,629
  • 2
  • 21
  • 43
2

GeoFire performs very well when we follow the recommended database structure.To know more about the best way to structure your data with goefire checkout this linkRecommended database structure with GEOFIRE

Now there are following way you can improve your query to get results fast even though I don't know your exact use case this may be helpful

  1. If you have very large data set try to make multiple query in increasing radius.(this approach is good if you are not performing any operation that requires all data at a time)

  2. If you want to keep better user experience you can put minimum required matches in keyEntered method of geofire query and show that result instead of waiting for all the matches.(This is helpful if you are showing data in listview or recyclerView )

Community
  • 1
  • 1
Guru
  • 286
  • 3
  • 6
2

Make sure that you only store the GeoHash and Lat / Lon data in your geofire collection. If you need to store other data, you would store that in another collection with the same key and issue a separate query to get back that data as required.

I use this structure, which seems to work well.

app-id
-> geodata
--> geofire
---> key
----> g: <geohash>
-----> l: 
-------> 0: Lat
-------> 1: Lon

--> other
---> key
----> <otherhash object>

When you save data you will separately save the geofire data using:

mDatabase = FirebaseDatabase.getInstance().getReference("geodata");      

geoFire = new GeoFire(mDatabase.child("geofire"));

geoFire.setLocation(people.key, new GeoLocation(people.Lat, people.Lon));

Then you would separately save your data in firebase:

    mDatabase = FirebaseDatabase.getInstance().getReference("geodata");

    mDatabase.child("other").child(people.key).setValue(people);

Hope this helps. :)

pvella
  • 190
  • 1
  • 9