swift - 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 米打印一次,但是它会在未预料到的情况下触发,并且我失去了解决方案或可能的问题。
解决方案
你不能依赖startMonitoringSignificantLocationChanges()
给你一致的结果。如果你去一个蜂窝塔密度低的区域,在它被触发之前你必须移动的距离将再次改变。这是一种低功耗、低可靠性的定位方法。
话虽如此,它在您没有移动时触发是不寻常的。也许您的设备切换了手机信号塔?也许这是一个错误。提交报告,创建一个小型测试项目并将其与您的日志文件一起发送给 Apple。
我不知道您的要求,但一种解决方案是保存(在实例变量中并作为文件)最后找到的位置并比较该位置与新位置之间的距离,看看您是否真的移动了很长的路。另一种是使用区域监控。
推荐阅读
- javascript - 在整页加载之前不要加载 div
- flutter - Flutter Moor:如果我对同一个表有多个引用,如何制作选择语句?
- algorithm - N叉树中BFS的复杂度
- cuda - “'long double' 在设备代码中被视为 'double'”的 NVCC 警告标记是什么?
- typescript - 你能得到一个基类型的所有子类型的联合吗?
- c# - XUnit Mock 没有像我期望的那样抛出异常
- reactjs - 使用 React 时 Vs 代码在 UI 中显示红色和黄色
- pentaho - 有没有一种方法可以通过脚本将 PDI 作业和转换从版本 6 升级到 9
- postgresql - Windows 的实际 PostgreSQL 下载 URL 是什么?
- angular - 离子存储不能与多个服务一起使用