PHP 计算两经纬度之间距离

热门标签

php 之间 纬度 计算 距离
<?php
  /*
    $lat1 纬度A
    $lon1 经度A

    $lat2 纬度B
    $lon2 经度B
    */
    function nearby_distance($lat1,&nbsp;$lon1, $lat2,&nbsp;$lon2) {
        $EARTH_RADIUS = 6378.137;
        $radLat1&nbsp;=&nbsp;rad($lat1);
        $radLat2&nbsp;=&nbsp;rad($lat2);
        $a&nbsp;=&nbsp;$radLat1 - $radLat2;
        $b&nbsp;=&nbsp;rad($lon1) - rad($lon2);
        $s&nbsp;=&nbsp;2&nbsp;*&nbsp;asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1)&nbsp;*&nbsp;cos($radLat2) * pow(sin($b / 2), 2)));
        $s1&nbsp;=&nbsp;$s * $EARTH_RADIUS;
        $s2&nbsp;=&nbsp;round($s1 * 10000) / 10000;
        return $s2;
        //print_r($s2);
    }
    function rad($d) {
        return $d * 3.1415926535898 / 180.0;
    }

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

评论 (0)