Hy!
我需要计算 2 个 GPS 点之间的距离。
我读了这个问题计算地理邻近度的公式 https://stackoverflow.com/questions/2096385/formulas-to-calculate-geo-proximity但我的英语太差了。
我的问题是这2个点最多相距1公里。
由于距离很小,我需要最精确的公式
PHP 或伪代码的示例会很棒
See 这一页 http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe。它包含大圆距离 http://en.wikipedia.org/wiki/Great-circle_distance各种编程语言的计算函数。
In PHP:
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371; // In the unit you want the result in.
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;
return $d;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)