php 根据经纬度计算两点之间的距离

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;
}

longitude  经度                  latitude   纬度 

经纬度的查询地址:

https://www.d1xz.net/xp/jingwei/

猜你喜欢

转载自blog.csdn.net/qq_37138818/article/details/81395081