我正在为IOS制作一个具有持久性对象的AR应用程序。然后,我在AR场景中放置的每个对象都与GPS位置一起存储。问题是:准确性。我使用的是swift的核心定位工具包,但在室内我无法获得低于4-6的精度(距离正确位置4-6米的误差)。然后在重新加载场景时,所有内容都会转移到其他地方。
我已经在用了
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
我试图得到几个样本来做加权平均,但我注意到在一些样本之后,获得的位置是相同的(精度也是4-6)。可能是斯威夫特自己做的。
我是不是漏掉了什么?一种获得更好方法的数学方法?还是没有更好的办法?
编辑
地点的速度如何?我应该更相信那些速度更快的人,还是说它根本不相关?
发布于 2018-09-20 12:36:12
我尝试了以下方法来跳过冗余的位置更新触发器。这种方法包括在您的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
}
}
}
https://stackoverflow.com/questions/52416273
复制相似问题