How can I use a GeoQuery to sort by both location and certain value? (Android)

守給你的承諾、 提交于 2019-12-04 05:48:01

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/55329334/how-can-i-use-a-geoquery-to-sort-by-both-location-and-certain-value-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!