DarshanGowda0 / GeoFlutterFire

:fire:GeoFlutterFire:fire: is an open-source library that allows you to store and query firestore documents based on their geographic location.
https://youtu.be/MYHVyl-juUk
MIT License
305 stars 261 forks source link

How to sort in order of closest? #182

Open son opened 2 years ago

son commented 2 years ago

Thank you for the wonderful package. How can I sort and query the data in order of closeness?

LogicNg commented 2 years ago

If you want to have the documents sorted by distance, you have to do that after the query. To get the distance of the coordinates from a given point, you can use the haversine formula.

LogicNg commented 2 years ago

Things get more complicated if you want to sort them with geohashes only. Nearby places have similar prefixes. The longer a shared prefix is, the closer the two places are. Two points can be very close but have no shared prefix. That means you have to run multiple queries, one for each sector around the center.