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

下面是PHP计算两个GPS点距离的函数:

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

#lon为ç»åº¦ï¼lat为纬度ï¼ä¸å®ä¸è¦å¼éäºå¦ function <span class='wp_keywordlink_affiliate'><a href="http://www.aiezu.com/tag/distance" title="æ¥ç distance 中çå¨é¨æç« " target="_blank">distance</a></span>($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; }

1

2

3

4

5

6

7

8

9

10

11

12

13

    #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);

1

echo distance(39.91917,116.3896,39.91726,116.3940);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值