我有一张经度/纬度坐标表
我需要的是从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来从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/

10-10 08:49