php计算两个坐标直线距离
1 function rad($d) 2 { 3 return $d * 3.1415926535898 / 180.0; 4 } 5 function GetDistance($lat1, $lng1, $lat2, $lng2) 6 { 7 $EARTH_RADIUS = 6378.137; 8 $radLat1 = rad($lat1); 9 //echo $radLat1; 10 $radLat2 = rad($lat2); 11 $a = $radLat1 - $radLat2; 12 $b = rad($lng1) - rad($lng2); 13 $s = 2 * asin(sqrt(pow(sin($a/2),2) + 14 cos($radLat1)*cos($radLat2)*pow(sin($b/2),2))); 15 $s = $s *$EARTH_RADIUS; 16 $s = round($s * 10000) / 10000; 17 return $s; 18 }
破罐子互摔