Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to sort in order of closest? #182

Open
son opened this issue Mar 21, 2022 · 2 comments
Open

How to sort in order of closest? #182

son opened this issue Mar 21, 2022 · 2 comments

Comments

@son
Copy link

son commented Mar 21, 2022

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

@LogicNg
Copy link

LogicNg commented Jun 27, 2022

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
Copy link

LogicNg commented Jun 27, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants