gpt4 book ai didi

php - GreatCircle 和 mysql 查询

转载 作者:行者123 更新时间:2023-11-29 09:07:31 25 4
gpt4 key购买 nike

我有一张带有经/纬度坐标的表格我需要的是从mysql表中获取距给定坐标一定距离的用户(可以是圆形或方形)

我使用 GreatCircle 类 ( Great Circle Distance question ) 获取距起点一定距离的东北西南坐标:

$distance = 300;

$GreatCircle = new GreatCircle();

// North
$new_coordinates = $GreatCircle->getPositionByDistance($distance, 0, $lon, $lat);
$N_lon = $new_coordinates['lon'];
//$N_lat = $new_coordinates['lat'];

// East
$new_coordinates = $GreatCircle->getPositionByDistance($distance, 90, $lon, $lat);
//$E_lon = $new_coordinates['lon'];
$E_lat = $new_coordinates['lat'];

// South
$new_coordinates = $GreatCircle->getPositionByDistance($distance, 180, $lon, $lat);
$S_lon = $new_coordinates['lon'];
//$S_lat = $new_coordinates['lat'];

// West
$new_coordinates = $GreatCircle->getPositionByDistance($distance, 270, $lon, $lat);
//$W_lon = $new_coordinates['lon'];
$W_lat = $new_coordinates['lat'];

现在,我可以创建这样的sql来从我的 table 上获取周围300米的其他坐标吗?

$GreatCircle = 
"l.longitude <= $E_lon
AND l.latitude <= $N_lat
AND l.longitude >= $W_lon
AND l.latitude >= $S_lat";

最佳答案

如果你不介意正方形,那就可以了。 (尽管请记住,有时纬度/经度值是负数......)

通常,您会将两组纬度/经度对传递给函数,并返回距离作为结果。那么你只需检查距离是否在你的限制之内。 (这将是圆形版本)

关于php - GreatCircle 和 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6649862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com