主页 > 编程资料 > PHP >
发布时间:2015-01-12 作者:网络 阅读:157次


 #lon为经度,lat为纬度,一定不要弄错了哦
    function distance($lon1, $lat1, $lon2, $lat2){
        return (2*ATAN2(SQRT(SIN(($lat1-$lat2)*PI()/180/2)
        *SIN(($lat1-$lat2)*PI()/180/2)+
        COS($lat2*PI()/180)*COS($lat1*PI()/180)
        *SIN(($lon1-$lon2)*PI()/180/2)
        *SIN(($lon1-$lon2)*PI()/180/2)),
        SQRT(1-SIN(($lat1-$lat2)*PI()/180/2)
        *SIN(($lat1-$lat2)*PI()/180/2)
        +COS($lat2*PI()/180)*COS($lat1*PI()/180)
        *SIN(($lon1-$lon2)*PI()/180/2)
        *SIN(($lon1-$lon2)*PI()/180/2))))*6378140;
    }

调用方法:echo distance(39.91917,116.3896,39.91726,116.3940);


 
关键字词: