PHP计算两个GPS坐标点之间的距离

PHP计算两个GPS坐标距离自定义函数:
#lng为经度,lat为纬度,一定不要弄错了哦
function distance($lat1, $lng1, $lat2, $lng2){
    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(($lng1-$lng2)*PI()/180/2)
    *SIN(($lng1-$lng2)*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(($lng1-$lng2)*PI()/180/2)
    *SIN(($lng1-$lng2)*PI()/180/2))))*6378140;
}
用法:
echo distance(39.91917,116.3896,39.91726,116.3940);
// 输出结果:431.65898565454
 
Mysql数据库中计算两GPS坐标的距离: http://aiezu.com/article/19.html
Javascript计算两个GPS坐标的距离: http://aiezu.com/article/17.html

更多关于GPS计算请参考:http://www.movable-type.co.uk/scripts/latlong.html(被墙)

0 个评论

要回复文章请先登录注册