How to find the nearest geohash in mysql?

大城市里の小女人 提交于 2019-12-13 04:58:45

问题


Recently I'm using GeoHash to hash the paired geo-coordinates into a hash value and store it in MySQL. Now I want to find the nearest hash given the other hash. I noticed that MYSQL provide BTree structure to find a range of nearest hashes by using the command "like" in SQL query.

The problem is, how could I find the nearest one instead of giving a range since sometimes I don't know the range.

Could someone give me a hint?

Really appreciate it.


回答1:


QuadTile (or GeoHash?) reversibly turns latitude + longitude into a single number. But to use it to "find nearest" gets complex and messy. Read about Z-ordering. As I understand it, you would need to run 4 queries with ORDER BY and LIMIT; UNION the results together; then check to see which are best.

But it gets tricky to know what to do if the attempt did not find enough items.

SPATIAL indexes provide a more straightforward way.

Here is a technique for efficiently "finding nearest" for large datasets.



来源:https://stackoverflow.com/questions/52229304/how-to-find-the-nearest-geohash-in-mysql

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