如何在速度测量期间摆脱不可预测的速度峰值?

时间:2018-04-20 09:59:18

标签: swift geolocation location core-location

我为用户速度跟踪编写了服务。此服务使用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经理吗?

1 个答案:

答案 0 :(得分:2)

我建议使用中位数过滤器来减少数据峰值。定义检测峰值的阈值并对其应用过滤器。请参阅此文档https://homepages.inf.ed.ac.uk/rbf/HIPR2/median.htm