1

在php中获取到两个经纬度,如何计算出两个经纬度之间的距离,可以参考:

$lng1=118.88812984364158;  //经度1
$lat1=31.947418655302248;   //纬度1
$lng2=118.88782102099347;  //经度2
$lat2=31.947298390448976;   //纬度2
$EARTH_RADIUS = 6378137;   //地球半径
$RAD = pi() / 180.0;
$radLat1 = $lat1 * $RAD;
$radLat2 = $lat2 * $RAD;
$a = $radLat1 - $radLat2;    // 两点纬度差
$b = ($lng1 - $lng2) * $RAD;  // 两点经度差
$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;
print_r($s);   //两个经纬度之间的距离

原文地址:https://blog.csdn.net/qq_3825...


huaweichenai
635 声望114 粉丝