The new Firestore DB allows me to store GeoPoints. Is there a way to query based on them?
So for example if each of my collections documents got a location
field of the type geopoint
. How can I get the closest 10 documents to an arbitrary coordinate?
The documentation doesn't seem to cover this. I tried stuff like this:
someRef.where('location', '>', geopoint).limit(10).get();
Obviously this doesn't make much sense but I'm just trying out some stuff here 😅
Is there any way to get the last created document in Firebase Firestore collection? Yes, there is! The simplest way to achieve this is to add a date property to each object in your collection, then simply query it according to this new property descending and call limit(1) function. That's it!
GeoFirestore is an open-source library for Android that allows you to store and query a set of documents based on their geographic location. At its heart, GeoFirestore simply stores locations with string keys.
You can find your Realtime Database URL in the Realtime Database section of the Firebase console. Depending on the location of the database, the database URL will be in one of the following forms: https:// DATABASE_NAME . firebaseio.com (for databases in us-central1 )
We haven't exposed geoqueries yet, so currently there isn't a way to do this.
Historically, the Firebase Realtime Database used geohashes in a library called GeoFire--but given that we plan to expose actual geoqueries in the near future, we haven't updated that library to Firestore. To learn how to do something similar yourself though, have a look at this video.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With