Is there a way to use GeoFire with Firestore?
GREAT NEWS. There is now a library for both iOS and Android that replicates GeoFire for Firestore. The library is called GeoFirestore. It has full documentation and is well tested. I currently use it in my app and it works brilliantly. The code is very similar to that of GeoFire so it should only take a few minutes to learn.
How can I use a GeoQuery to sort by both location and certain value? (Android)
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 every 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
Filtering results with Geofire + Firebase
Firebase queries can only filter by one condition. Geofire already does quite some "magic" to allow it to filter on both longitude and latitude. Adding another property to that equation might be possible, but is well beyond what Geofire handles by default. See GeoFire: How to add extra conditions within the query?
If you only ever want to access one category at a time, you can put the restaurants in a top-level node per category and point Geofire to one category.
/category1
item1
g: "pns0h0mf2u"
l: [-53.435719, 140.808716]
item2
g: "u417k3dwub"
l: [56.83069, 1.94822]
/category2
item3
g: "8m3rz3s480"
l: [30.902225, -166.66809]
/items
item1: ...
item2: ...
item3: ...
In the above example, we have two categories: category1
with 2 items and category2
with just 1 item. For each item, we see the data that Geofire uses: a geohash and the longitude and latitude. We also keep a single list with the other properties of these 3 items.
But more commonly, you simply do the extra filtering in client-side code. If you're worried about the performance of that: measure it, share the code, JSON data and measurements.
Related Topics
Why Does Somestruct() Is Anyobject Return True
Concatenate Literal with Optional String
How to Handle Parameter Validation Swift
Swiftui - Make Toolbar's Navigationlink Use Detail View
Swift For-In Loop with Enumerate on Custom Array2D Class
How to Move Platform with Velocity
In Swift, Can One Use a String to Access a Struct Property
Why Strings Are Not Equal in My Case
Swift Lazy Stored Property Versus Regular Stored Property When Using Closure
How to Use Spritekit Archives with Skspritenode Subclasses
Swift 3: Int Is Not Convertible to Bool in Bitwise Operation
Limiting Concurrent Access to a Service Class with Rxswift
What Does T Equals T Mean in Generics
Inferred to Have Type 'Anyclass', Which May Be Unexpected