亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過坐標計算 GPS 點之間的距離

通過坐標計算 GPS 點之間的距離

PHP
喵喔喔 2022-01-14 17:09:55
我在通過坐標計算兩個 GPS 點之間的距離時遇到了一些麻煩。point ax = 7,2562y = 47,7434599999999point b x = 7,21978y = 47,73836我使用了此處描述的 Haversine 公式。我得到的結果是 4.09 公里。但是,使用這樣的工具在地圖上定位這些點,我可以測量2.8 公里的距離我嘗試的其他幾個公式也返回了大約 4 公里的結果。有什么想法我會錯過嗎?
查看完整描述

1 回答

?
慕仙森

TA貢獻1827條經驗 獲得超8個贊

我認為是因為你以英里為單位使用該功能,在公里中你可以使用類似的東西:


    public static function distance(

        array $from,

        array $to

    ) {

        if (empty($from['lat']) || empty($to['lat'])) {

            return $to['distance'];

        }


        $latitude1  = (float) $from['lat'];

        $latitude2  = (float) $to['lat'];

        $longitude1 = (float) $from['lng'];

        $longitude2 = (float) $to['lng'];


        $theta = $longitude1 - $longitude2;

        $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2)))

            + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)))

        ;

        $distance = acos($distance);

        $distance = rad2deg($distance);

        $distance = $distance * 60 * 1.1515;

        $distance = (is_nan($distance)) ? 0 : $distance * 1.609344;


        return  $distance;

    }


查看完整回答
反對 回復 2022-01-14
  • 1 回答
  • 0 關注
  • 272 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號