【发布时间】:2014-02-17 12:02:05
【问题描述】:
这是我的代码,它给出了结果。
我使用了班格罗尔艾哈迈达巴德的坐标点。 距离差异应该接近 1500,但在这里我得到 32200
function points{
$lat_a = 12.96;
$lon_a = 77.56;
$lat_b = 23.03;
$lon_b = 72.58;
$earth_radius = 6372.795477598;
$delta_lat = $lat_b - $lat_a ;
$delta_lon = $lon_b - $lon_a ;
$a = pow(sin($delta_lat/2), 2);
$a += cos(deg2rad($lat_a)) * cos(deg2rad($lat_b)) * pow(sin(deg2rad($delta_lon/29)), 2);
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
$distance = 2 * $earth_radius * $c;
$distance = round($distance, 4);
echo "<br/>dist $distance";
}
【问题讨论】:
-
距离应该是929.5 英里,你用的是什么UOM?
-
sin() 和 cos() 期望以弧度输入;您正在使用初始化 $a 的度数
-
pow(sin(deg2rad($delta_lon/29)), 2)...29从何而来? -
@MarkBaker:正确指出。让我检查一下
标签: php geolocation geo