startMonitoringSignificantLocationChanges在静止时触发

问题描述 投票:3回答:2

我有一个客户端的应用程序,要求我使用startMonitoringSignificantLocationChanges()方法,但是当我静止并且没有移动一段时间时,它仍然会触发。

我的位置管理器代码如下:

        locationManager = CLLocationManager()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.distanceFilter = 1500
        locationManager.startUpdatingLocation()
        locationManager.delegate = self
        locationManager.startMonitoringSignificantLocationChanges()
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.pausesLocationUpdatesAutomatically = false

然后我的didUpdateLocations

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location: CLLocation = locations.last!
        print("Location: \(location)")

        print("SIGNIFICANT CHANGE")

    }

当我旅行时,它按照预期每1500米打印,但是当没有预料到它时会触发,我失去了解决方案或可能的问题。

swift core-location
2个回答
1
投票

activityType会帮忙吗?

既然您正在使用它来旅行,您可能会忽略步行或非汽车运动?

如果这不是一个选项,您可以尝试在didUpdateLocations中计算CLLocation对象的水平/垂直精度。如果不在阈值范围内则忽略(这可能会导致一些漏报)


1
投票

你不能依靠startMonitoringSignificantLocationChanges()来给你一致的结果。如果你去一个单元塔密度低的区域,你在触发之前必须移动的距离将再次改变。这是一种低功耗定位方法,可靠性低。

话虽这么说,但是当你没有移动时触发它是不寻常的。也许你的设备切换了电池塔?也许这是一个错误。提交报告,制作一个小型测试项目,并将其与您的日志文件一起发送给Apple。

我不知道你的要求,但一个解决方案是保存(在实例变量和文件中)最后找到的位置,并比较它与新位置之间的距离,看看你是否真的移动了很长的路。另一种是使用区域监测。

© www.soinside.com 2019 - 2024. All rights reserved.