This is a Geoquery for Firestore: https://github.com/imperiumlabs/GeoFirestore-Android But it doesn't allow for further sorting. I want to sort by the nearest and most famous users, how could i do such a thing? Are there any other possible libraries?
-
Also posted on https://www.reddit.com/r/Firebase/comments/b52ogt/how_can_i_use_the_geofirestore_library_to_sort_by/ – Frank van Puffelen Mar 25 '19 at 00:11
1 Answers
Geofire already does something seemingly impossible on Firestore: it performs a range query on two values (lat and lon). It does this by creating a geohash value, which combines the latitude and longitude into a single value, that can be used to select a range of documents that are close to each other.
To allow additionally select on the range of another field, you'd have to find a way to combine the value of that other field into the Geohash value. It essentially means you have to find a way to express the importance of fame (your additional property) as a function of location (the distance), and compute a single field value based on that. While this may technically possible, I doubt anyone has ever done it.
To learn how filtering on location works (and why adding an extra field is not as simple as it may seem), have a look at:
- the video of my talk on geofiltering on Firestore
- Jeff's much more concise Realtime GeoQueries With Firestore video and article
- Firebase/GeoFire - Most popular item at location

- 2,255
- 2
- 18
- 30

- 565,676
- 79
- 828
- 807
-
Will Firestore's eventual native geoquerying use geohashes and work like GeoFire or will it work differently (i.e. using Google S2 Geometry)? – trndjc Apr 06 '19 at 18:36
-
Nobody has started work on this yet, so there's no sense speculating on how it will work. – Frank van Puffelen Apr 07 '19 at 02:33
-
This means that it is not possible (or at least, very hard...) to combine any 'where' with a geoquery in Firebase or Firestore, is this correct? – nibbana Apr 01 '20 at 17:06
-
It depends on the other `where`. Adding an additional equality check is possible, although I don't think any of the existing libraries allow that in their API. Adding an additional range check will indeed be much harder. – Frank van Puffelen Apr 01 '20 at 17:28
-
Thanks very much for your answer. So I understand that it is possible, but does Firestore allow that? For example, is it possible in Firestore a query such as: db.collection('places') .orderBy("geoHash") .where('geoHash', '>=', range.lower) .where('geoHash', '<=', range.upper) .where("cities", "array-contains", "rome") .limit(15).get() I can ask a new question if necessary of course – nibbana Apr 01 '20 at 17:49
-
1Yeah, that looks possible. If you run into problems, that'd be a good moment to post a new question. :) – Frank van Puffelen Apr 01 '20 at 23:18