在iOS上获得即时速度的最准确方法是什么?

时间:2013-09-18 13:41:04

标签: ios objective-c performance gps cllocation

我目前正致力于健康/健身应用程序,该应用程序应该跟踪用户在锻炼期间的瞬时速度(跑步,骑自行车,等等......)。应用程序必须能够提供实时指令,因此速度必须尽可能准确并且经常刷新。

我已经找到了一个很好的教程here,其中使用距离和时间计算当前速度,并使用之前计算的3个速度进行平均。如果我改变了一些定义,这似乎可以完成这项工作,但整个代码对于这么简单的事情来说有点复杂。另外,我知道CLLocation类具有speed属性,可以提供相同的信息。

所以我的问题是:哪种方式获得瞬时速度最准确?或者换句话说,CLLocation的{​​{1}}属性是否足以满足此类用途?

谢谢!

2 个答案:

答案 0 :(得分:0)

来自Apple Reference

speed
The instantaneous speed of the device in meters per second.

@property(readonly, NS_NONATOMIC_IPHONEONLY) CLLocationSpeed speed
Discussion
This value reflects the instantaneous speed of the device in the direction of its current heading. A negative value indicates an invalid speed. Because the actual speed can change many times between the delivery of subsequent location events, you should use this property for informational purposes only.

Special Considerations
In iOS, this property is declared as nonatomic. In OS X, it is declared as atomic.

Availability
Available in OS X v10.7 and later.
Declared In
CLLocation.h

听起来不像Apple认为它准确。也不是。

编辑 - 这是related question同样的问题和一些建议。

答案 1 :(得分:0)

您可以获得的最佳价值是GPS速度。因此,请确保已将GPS设置为AccuracyBest并读取CLLocation speed属性。

您移动的速度越慢,就像所有GPS设备一样。 对于汽车典型速度,您可以获得0.1 km / h的精度。