将lat / lng与另一个lat / lng进行比较

时间:2013-04-19 16:00:02

标签: php mysql

我在数据库中有我们存储的纬度和经度的场地。

我也有登录用户的纬度和经度。

我正在开发一个功能,允许他们在任何给定的测量范围内找到场地,比如20英里。

是否有可能找到距离用户的纬度20英里的最长的纬度和长距离,然后以某种方式编写查询以查找MySQL中距离圈内的场地?

感谢。

2 个答案:

答案 0 :(得分:1)

我使用它(从javascript移植到Objective-C) - 用javascript http://www.movable-type.co.uk/scripts/latlong.html

表示的很多很棒的位置方程式

答案 1 :(得分:1)

我发现了一个有效的PHP函数:

function getDistanceBetweenPoints($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi') {

    $theta = $longitude1 - $longitude2;
    $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $distance = acos($distance);
    $distance = rad2deg($distance);
    $distance = $distance * 60 * 1.1515; switch($unit) {
        case 'Mi': break; case 'Km' : $distance = $distance * 1.609344;
    }
    return (round($distance,2));

}  

认为这可能有助于其他人。