ios - 有没有办法在 GPS 给出的位置上获得更好的精度?
问题描述
我正在为带有持久对象的 IOS 制作 AR 应用程序。然后,我放置在 AR 场景中的每个对象都存储有 GPS 位置。问题是:准确性。我正在使用 swift 的核心定位套件,但在室内我不能得到低于 4-6 的精度(距离正确位置 4-6 米的误差)。随着重新加载场景,一切都在其他地方。
我已经在使用
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
我试着让几个样本做一个加权平均,但我注意到在一些样本之后获得的位置是相同的(精度也是 4-6)。可能斯威夫特是他自己做的。
有什么我想念的吗?获得更好方法的数学方法?或者没有办法让它变得更好?
编辑
一个位置的速度呢?我应该信任更多速度更快的人还是根本不相关?
解决方案
我尝试了以下方法来跳过冗余位置更新触发器。此方法包括在您的 UserDefaults 中保存最新的位置更新。并且下次接收到位置更新时,在接受该位置作为有效位置更新之前,会进行一系列检查,例如位置准确性、更新时间戳、距离等。希望这可以帮助。
func setCurrentLocation(location: CLLocation) {
let encodedLocation = NSKeyedArchiver.archivedData(withRootObject: location)
UserDefaults.standard.set(encodedLocation, forKey: UserDefaultKey.previousVisitedLocation)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard locations.count > 0 else {
return
}
guard let location = locations.last else {
return
}
guard location.horizontalAccuracy > 0 else {
return
}
guard location.horizontalAccuracy < DISTANCE_LIMIT else { //DISTANCE_LIMIT is the value you have set for your distance filter
return
}
let previousLocationEncoded = UserDefaults.standard.object(forKey: UserDefaultKey.previousVisitedLocation) as? Data
if previousLocationEncoded == nil {
setCurrentLocation(location: location)
//do your tasks
} else {
let previousLocationDecoded = NSKeyedUnarchiver.unarchiveObject(with: previousLocationEncoded!) as! CLLocation
let distanceBetweenVisits = previousLocationDecoded.distance(from: location)
if distanceBetweenVisits > DISTANCE_LIMIT {
let timeIntervalBetweenVisits = location.timestamp.timeIntervalSince(previousLocationDecoded.timestamp)
guard timeIntervalBetweenVisits > 0 else {
return
}
setCurrentLocation(location: location)
//do your tasks
}
}
}
推荐阅读
- javascript - 数据表是如何工作的?
- python - 如果我使用 app_label='auth' 添加自定义模型(租户),Django makemigrations 会引发错误
- javascript - 如何在 Laravel 中自定义 vue-filemanager 前端?
- jquery - toggleClass 不工作,$ 不是函数
- c# - “oncollisionenter”中的 Rigidbody.Addforce 未在统一 c# 中执行
- javascript - 通过从 Google Sheet 生成的数组进行交互 | Google Apps 脚本
- javascript - 如果在反应组件内返回语句
- prometheus - 跨多个实例查询 prometheus 计数器
- python - 集合的 Pyyaml 自定义解析器
- google-apps-script - 在谷歌表格上自动刷新与 plx 的连接