OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 distanceFromLocation : 的距离错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 23:58
标题: ios - 使用 distanceFromLocation : 的距离错误

我正在尝试找出问题所在,但似乎上述方法只是返回了错误的值。我在模拟器中设置坐标,然后打印它们并计算距离:

(lldb) p location.coordinate
(CLLocationCoordinate2D) $1 = (latitude = 51, longitude = 0.10000000000000001)
(lldb) p _oldLocation.coordinate
(CLLocationCoordinate2D) $2 = (latitude = 51, longitude = 0)

现在我正在计算距离:

distance = (CGFloat)[location distanceFromLocation:_trackEndLocation];

当我打印它时,我得到:

(lldb) po self.trackDistance
7019.76758

现在,问题是用户告诉我应用返回的距离太远。因为我想调试它,所以我检查了 page to calculate distance between two points 的距离.

结果如下:

enter image description here

如您所见,网页上的距离是 6.997 公里,而 Apple 方法告诉我的距离是 7.019 公里。我想知道谁是不正确的,Apple 或网页以及如何处理这件事。差异不大,但是当您在几个点之间累积时,可能会令人不安。



Best Answer-推荐答案


distanceFromLocation 的 Apple 文档页面这样说:

This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations.

我怀疑 Google map 确实考虑了两点之间的地形,这就是为什么您在测试中看到 0.3% 的差异。但是,我怀疑您的客户是否在提示这种级别的错误。错误更有可能来自不同的原因。

如果不了解您的算法的更多信息,很难说,但如果您正在跟踪行驶距离,则错误可能是由手机 GPS 坐标中的抖动引起的。 (这会导致直线路径看起来像锯齿形,从而产生更长的距离。)您可以从您的应用中记录一些真实数据以确保查看。

关于ios - 使用 distanceFromLocation : 的距离错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24905536/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4