【发布时间】:2018-10-01 00:24:21
【问题描述】:
我编写了用户速度跟踪服务。该服务使用Core Location 框架来跟踪地理点并计算用户速度。
服务示例:
private func processLocation(_ current:CLLocation) {
guard let location = lastLocation else {
lastLocation = current
speed.value = 0
return
}
var speed = current.speed
if (speed > 0) {
speed.value = speed
} else {
speed = location.distance(from: current) / (current.timestamp.timeIntervalSince(location.timestamp))
speed.value = speed
}
lastLocation = current
}
此服务以可接受的准确性运行。但是有一种情况是,当您处于静止状态时,此服务会收到很多不可预测的峰值。
当我静止时记录。
Speed: 0.249200397696353
Speed: 0.778375328912623
Speed: 6.99212664940017 -> peak
Speed: 4.91809055561385 -> peak
Speed: 0.701735999364708
Speed: 0.025146066057472
Speed: 0.0233857682731226
Speed: 12.7814687721084 -> peak
Speed: 0.61632553168542
Speed: 7.37520678279276 -> peak
Speed: 0.023421072500409
Speed: 0.0343784939631481
Speed: 0.471982071125438
Speed: 0.0207671001927932
Speed: 0.0217459598583271
Speed: 0.0394697185852203
Speed: 0.439568634647097
Speed: 14.1348693612176 -> peak
Speed: 6.29588775714151 -> peak
Speed: 5.55254459904619 -> peak
Speed: 0.218587071425142
如何消除此速度跟踪服务中不可预测的峰值?我应该更好地配置Core Location 管理器吗?
【问题讨论】:
-
这些峰值是否来自距离计算?
-
@Scriptable 是的,你是正确的距离/时间
-
如果你想要更好的结果,你可以尝试结合 CoreMotion 和 CoreLocation 来优化它们,例如,如果你是静止的,你可以在某些速度阈值下进行过滤,等等。
标签: swift geolocation location core-location