经纬度计算距离的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xly1993/article/details/79270046
//计算距离
    //经度 ,纬度   经度,纬度
   public function getdistance($lng1, $lat1, $lng2, $lat2) {
    // 将角度转为狐度

    $radLat1 = deg2rad($lat1); 

  //deg2rad()函数将角度转换为弧度

    $radLat2 = deg2rad($lat2);
    $radLng1 = deg2rad($lng1);
    $radLng2 = deg2rad($lng2);
    $a = $radLat1 - $radLat2;
    $b = $radLng1 - $radLng2;
    $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000;
    return $s;

猜你喜欢

转载自blog.csdn.net/xly1993/article/details/79270046