首页 > 解决方案 > startMonitoringSignificantLocationChanges 在静止时触发

问题描述

我有一个需要我使用该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 米打印一次,但是它会在未预料到的情况下触发,并且我失去了解决方案或可能的问题。

标签: swiftcore-location

解决方案


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

话虽如此,它在您没有移动时触发是不寻常的。也许您的设备切换了手机信号塔?也许这是一个错误。提交报告,创建一个小型测试项目并将其与您的日志文件一起发送给 Apple。

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


推荐阅读