計算兩組經緯度座標間的距離,兩組/** * 計算兩組經緯度座標間的距離 * params:lat1緯度1,lng1經度1,lat2緯度2,lng2經度2,len_type(1:m|2:km); * echo getdistance($lat1,$lng1,$lat2,$lng2).'米'; */function getdistance($lat1,$lng1,$lat2,$lng2,$len_type=1,$decimal=2){ $earth_radius=6378.137; //地球半徑,假設地球是規則的球體 $pi=3.1415926; //圓周率 $radlat1 = $lat1 * $pi / 180.0; $radlat2 = $lat2 * $pi / 180.0; $a = $radlat1 - $radlat2; $b = ($lng1 * $pi / 180.0) - ($lng2 * $pi / 180.0); $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); if($len_type>1){ $s /= 1000; } return round($s,$decimal);}
http://www.bkjia.com/phpjc/940336.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/940336.htmltecharticle計算兩組經緯度座標間的距離,兩組 /** * 計算兩組經緯度座標間的距離 * params:lat1緯度1,lng1經度1,lat2緯度2,lng2經度2,len_type(1:m|2:km); * echo g...