<?php
print GetDistance('121.584406','31.264405','121.769956','31.052602');
function rad($d)
{
return $d * 3.1415926535898 / 180.0;
}
function GetDistance($lat1, $lng1, $lat2, $lng2)
{
$EARTH_RADIUS = 6378.137;
$radLat1 = rad($lat1);
$radLat2 = rad($lat2);
$a = $radLat1 - $radLat2;
$b = rad($lng1) - rad($lng2);
$s = 2 * asin(sqrt(pow(sin($a/2),2) +
cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));
$s = $s *$EARTH_RADIUS;
$s = round($s * 10000) / 10000;
return $s;
}
【转】php获取两经纬度之间的距离
最新推荐文章于 2021-03-24 18:16:07 发布