MySQL 可以选择行坐标 < 的位置吗距离目标坐标 x 英里? (mysql邻近搜索)

发布于 2024-09-06 18:10:23 字数 433 浏览 4 评论 0 原文

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等...)

There's a few questions like this on Stack Overflow but because i can't find any quite similar enough for me to follow.

I'm looking to select rows from db which are within x miles of a target.

example table columns:

| city_name(varchar) | lat(decimal) | lon(decimal) |

query effect i'm looking for (either using php or mysql)

$target_lat = ;
$target_lon = ;
"SELECT table.city_name WHERE (table.lat,table.lon) LESS THAN 20 MILES FROM ($target_lat,$target_lon")

obviously i don't expect query to take this structure! (i've never used Pi etc in mysql...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情绪失控 2024-09-13 18:10:23

听起来您正在寻找 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

倚栏听风 2024-09-13 18:10:23

我发现这非常出色并且非常容易理解

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

筱果果 2024-09-13 18:10:23

毕达哥拉斯定理指出,直角三角形斜边长度的平方等于其他两条边的平方和。

C^2 = A^2 + B^2
C = SQRT(A^2 + B^2)

在这种情况下,其他边的长度由纬度值和经度值的差异决定。在短距离内,这将为您提供相当好的近似值。然而,这仍然不能给你英里,这是一个更困难的转换,因为纬度/经度和英里之间没有固定的关系。相反,经度之间的距离随着纬度的变化而变化。

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.

C^2 = A^2 + B^2
C = SQRT(A^2 + B^2)

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.

北方的韩爷 2024-09-13 18:10:23

你会在谷歌搜索“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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文