2

我有以下数据:

  1. 当前位置 A. 纬度 B. 经度
  2. 用户身份

在我的数据库中,我有所有用户的纬度和经度

我想找出距离我当前位置 100 米范围内的所有用户。

我已经使用了一些示例,但它们显示相同纬度和经度的距离为 9 米,经纬度的小数点后 6 位。

我已经使用了以下代码

SELECT * , ((((acos( sin( ($lat * pi() /180 )) * sin((纬度* pi() /180) ) + cos( ( $lat * pi() /180 )) * cos((纬度* pi() /180)) * cos((( $lon -经度) * pi() /180 )))) *180 / pi()) *60 * 1.1515)*1.60934) AS距离FROM tablename where radar_status<>'0' 并且具有distance<'0.100' ORDER BY distanceASC 限制 1,10 谢谢

4

2 回答 2

3

请检查结果或检查链接

http://forums.asp.net/t/1325947.aspx/1

http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#PolesAnd180thMeridian

如果您传递当前用户的纬度、经度和您想要查找的距离,那么下面的查询将执行此操作。

SELECT * FROM(SELECT *,(((acos(sin((@latitude*pi()/180)) * sin((Latitude*pi()/180))+cos((@latitude*pi()/180)) * cos((Latitude*pi()/180)) * cos(((@longitude - Longitude)*pi()/180))))*180/pi())*60*1.1515*1.609344) as distance FROM Distances ) t  WHERE distance <= @distance

请也检查一下

$distance = 10;
$latitude = 37.295092;
$longitude = -121.896490;
$sql = "SELECT loc.*, (((acos(sin(($latitude*pi()/180)) * sin((`latitude`*pi()/180))+cos(($latitude*pi()/180)) * cos((`latitude`*pi()/180)) * cos((($longitude - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance` FROM table_with_lonlat_ref loc HAVING distance < $distance"
于 2013-08-22T11:34:43.957 回答
0

很少有公式可以做到这一点,看起来您正在使用余弦球面定律。您似乎正在转换为很好的弧度,看起来您也正在从地球半径转换为公里 - 但请查看以下内容:

1) 我假设你的 SQL 设置默认是弧度的?sin(pi/2)=1 等等。

2)我认为您在查询中过度转换为带有额外 pi/180 的弧度。试试这个作为您查询的内容。

尝试这个:

ACOS( SIN( $lat1*pi()/180 ) * SIN ( latitude*pi()/180 ) + COS( $lat*pi()/180 ) * COS ( latitude*pi()/180 ) * COS ( ($lon-longitude)*pi()/180))*63.71

找出括号可能会很棘手,但是

ACOS( SIN(lat1)*sin(lat2) + COS(lat1)*cos(lat2)*cos(lon1-lon2) ) * RadiusEarth

和所有的弧度角。地球半径与您的查询过滤器采用相同的单位,即您在 <0.100 上过滤时的公里

您的 *60*1.51 和其他 1.60 可能会给您一个虚假的结果 - 这些比例因子是否给您提供了地球半径以外的其他东西?

...缺口

于 2013-07-15T21:14:19.380 回答