通过坐标计算 GPS 点之间的距离

我在通过坐标计算两个 GPS 点之间的距离时遇到了一些麻烦。


point a

x = 7,2562

y = 47,7434599999999


point b 

x = 7,21978

y = 47,73836

我使用了此处描述的 Haversine 公式。我得到的结果是 4.09 公里。


但是,使用这样的工具在地图上定位这些点,我可以测量2.8 公里的距离


我尝试的其他几个公式也返回了大约 4 公里的结果。


有什么想法我会错过吗?


喵喔喔
浏览 281回答 1
1回答

慕仙森

我认为是因为你以英里为单位使用该功能,在公里中你可以使用类似的东西:    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;    }
打开App,查看更多内容
随时随地看视频慕课网APP