由两点经纬度计算距离之php实现

<?php
const EARTH_RADIUS = 6378.137;
function rad($d)
{
   return $d * M_PI / 180.0;
}

function GetDistance($lat1, $lng1, $lat2, $lng2)
{
   $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 * 1000);
   return $s;
}
echo GetDistance(39.994103,116.365338,40.037428,116.332334);// m

据称以上代码是copy自googlemap,我把他翻译成php版本,并将原输出结果km改成m