DeTechn Blog

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;
    }

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »