Ordering Firestore GeoHash query from closest to furthest?

后端 未结 1 1712
借酒劲吻你
借酒劲吻你 2021-01-16 02:52

Currently, I\'m using parts of the GeoFirebase library along with Firestore to allow for geoquerying. When I set the geohash of a post, I do it as such if let geoHash

相关标签:
1条回答
  • 2021-01-16 03:31

    GeoFirestore uses geohashes to be able to select documents that are within a range of geohashes, which is roughly the same as an area on the map. There is no way to retrieve those documents within a specified order from within that area with just a geoquery. If you want to have the documents sorted by distance, you will have to do that after the geoquery, in your application code.

    If you want to learn more on why that is, have a look at a talk I gave a while ago: Querying Firebase and Firestore based on geographic location or distance. In it I explain how geohashes work, how they allow you to select documents in a certain geographic range, and why you can't do the more complex query on Firestore (or Firebase's original realtime database).

    0 讨论(0)
提交回复
热议问题