gpt4 book ai didi

swift - 我怎样才能摆脱速度测量过程中不可预测的速度峰值?

转载 作者:可可西里 更新时间:2023-11-01 01:08:58 24 4
gpt4 key购买 nike

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

最佳答案

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

关于swift - 我怎样才能摆脱速度测量过程中不可预测的速度峰值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49939030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com