MySQL 可以选择行坐标 < 的位置吗距离目标坐标 x 英里? (mysql邻近搜索)
Stack Overflow 上有一些类似的问题,但因为我找不到足够相似的问题供我遵循。
我希望从数据库中选择距目标x英里以内的行。
示例表列:
| city_name(varchar) | lat(decimal) | lon(decimal) |
我正在寻找的查询效果(使用php或mysql)
$target_lat = ;
$target_lon = ;
"SELECT table.city_name WHERE (table.lat,table.lon) LESS THAN 20 MILES FROM ($target_lat,$target_lon")
显然我不期望查询采取这个结构! (我从来没有在mysql中使用过Pi等...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来您正在寻找 mySql 的地理空间包。这里列出了一个函数,可以检查两个纬度/经度点之间的距离。请记住,由于地球的曲率,常规距离计算不适用于纬度/经度。 =)
http://forge.mysql.com/wiki/GIS_Functions
It sounds like you're looking for a geo-spatial package for mySql. There's a function listed here that allows for distance checking between two lat/long points. Just remember that a regular distance calculation won't work with lat/long because of the Earth's curvature. =)
http://forge.mysql.com/wiki/GIS_Functions
我发现这非常出色并且非常容易理解
http://code.google .com/apis/maps/articles/phpsqlsearch.html
I found this which is brilliant and really easy to understand
http://code.google.com/apis/maps/articles/phpsqlsearch.html
毕达哥拉斯定理指出,直角三角形斜边长度的平方等于其他两条边的平方和。
在这种情况下,其他边的长度由纬度值和经度值的差异决定。在短距离内,这将为您提供相当好的近似值。然而,这仍然不能给你英里,这是一个更困难的转换,因为纬度/经度和英里之间没有固定的关系。相反,经度之间的距离随着纬度的变化而变化。
The Pythagorean theorem states that the square of the length of the hypotenuse of a right triangle is equal to the sum of the squares of the other two sides.
In this case, the lengths of the other sides are determined by the difference of your lat and long values. Over short distances this will give you a pretty good approximation. However, this still doesn't give you miles, which is a much more difficult conversion since there is not a fixed relationship between lat/long and miles. Instead, the distance between longitudes varies as a function of latitude.
你会在谷歌搜索“mysql radius search”中找到许多代码片段,
它们对于在这里复制来说有点太长了。
编辑: http://spinczyk .net/blog/2009/10/04/radius-search-with-google-maps-and-mysql/
you will find many code snippets in google searching for "mysql radius search"
they are a little bit too long for copying here.
Edit: http://spinczyk.net/blog/2009/10/04/radius-search-with-google-maps-and-mysql/