Ios 有没有办法提高GPS定位的精度?

Ios 有没有办法提高GPS定位的精度?,ios,swift,math,localization,Ios,Swift,Math,Localization,我正在为IOS制作一个AR应用程序,其中包含持久对象。 然后,我在AR场景中放置的每个对象都存储有GPS位置。问题是:准确性。 我使用的是swift的核心定位套件,但在室内我无法获得低于4-6的精度(距离正确位置4-6米的误差)。因此,在重新加载场景时,所有内容都会转到其他地方 我已经在用了 locationManager.desiredAccuracy=KCallocationAccuracyBestforNavigation 我试图获得几个样本进行加权平均,但我注意到,在一些样本之后,获得的

我正在为IOS制作一个AR应用程序,其中包含持久对象。 然后,我在AR场景中放置的每个对象都存储有GPS位置。问题是:准确性。 我使用的是swift的核心定位套件,但在室内我无法获得低于4-6的精度(距离正确位置4-6米的误差)。因此,在重新加载场景时,所有内容都会转到其他地方

我已经在用了

locationManager.desiredAccuracy=KCallocationAccuracyBestforNavigation

我试图获得几个样本进行加权平均,但我注意到,在一些样本之后,获得的位置是相同的(精度也是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
        }
    }
}
func setCurrentLocation(位置:CLLocation){
让encodedLocation=NSKeyedArchiver.archivedData(withRootObject:location)
UserDefaults.standard.set(encodedLocation,forKey:UserDefaultKey.previousVisitedLocation)
}
func locationManager(manager:CLLocationManager,didUpdateLocations位置:[CLLocation]){
防护位置。计数>0其他{
返回
}
防护装置位置=位置。最后一个位置{
返回
}
防护位置。水平精度>0其他{
返回
}
guard location.HorizontalAccurance<距离\限制else{//距离\限制是您为距离过滤器设置的值
返回
}
将previousLocationEncoded=UserDefaults.standard.object(forKey:UserDefaultKey.previousVisitedLocation)设为?数据
如果previousLocationEncoded==nil{
setCurrentLocation(位置:位置)
//完成你的任务
}否则{
将previousLocationDecoded=NSKeyedUnarchiver.unarchiveObject(带:previousLocationEncoded!)设为!CLLocation
让distanceBetweenVisits=previousLocationDecoded。距离(from:location)
如果访客之间的距离>距离限制{
让timeIntervalBetweenVisits=location.timestamp.timeIntervalSince(previousLocationDecoded.timestamp)
访问之间的保护时间间隔>0其他{
返回
}
setCurrentLocation(位置:位置)
//完成你的任务
}
}
}

kCLOCATIONACURACYBESTFORNAVISION确实是iOS提供的最准确的表示。如果你的平均值被同一个读的频繁更新所歪曲,你可以考虑实现<代码> DistaseFiels(参见)只有当用户移动某个阈值时才会更新,因此不会向平均值中添加那么多读数。您可能希望读取所有相同的样本,因为我拿着手机站着不动。我认为,保持同样的位置,然后平均结果可能会奏效。但是在4-5个位置之后,所有的后续结果都是一样的:DI得到的位置是静止不动的。试着四处走动,似乎好了一点。但通过这种方式,我可以检索已保存的对象,但无法存储它们。我的意思是:当我得到“想要的”iPhone位置时,我会重置AR场景的原点。因此它们是对齐的,我可以添加相对于该位置和AR原点的对象。无论如何,您的方法对于检索对象、在位置更新时重新加载场景可能很有用。