CLLocationManager的startMonitoringSignificantLocationChanges()和startUpdatingLocation()方法之间有什么区别?

Bha*_*eja 5 objective-c cllocationmanager cllocation ios swift

我在CLLocationManager上课。我想定期获取位置更新。我发现了两种方法来获取方法中的位置didUpdateLocations,分别是startUpdatingLocation()startMonitoringSignificantLocationChanges()。如果必须在前台模式下跟踪位置更新,那么我应该使用哪种方法?

Guy*_*her 5

两者之间最重要的区别是:

startMonitoringSignificantLocationChanges:它不依赖于distanceFilter属性中的值来生成事件。仅当检测到用户位置发生重大变化时,接收器才会生成更新事件

startUpdatingLocation:接收器主要在超过distanceFilter属性中的值时生成更新事件

因此,如果您想要更高的精度,请选择startUpdatingLocation,以消耗更多的电池电量为代价,但要提高位置的精度。这实际上取决于您的目标,您应该评估权衡。


Vis*_*kar 4

\n

startMonitoringSignificantLocationChanges 异步启动位置事件的传递,并在您调用它后不久返回。位置事件将传递到您的 delegate\xe2\x80\x99s locationManager:didUpdateLocations: 方法。要传递的第一个事件通常是最近缓存的位置事件(如果有),但在某些情况下可能是较新的事件。返回当前位置修复后,仅当检测到 user\xe2\x80\x99s 位置发生重大更改时,接收器才会生成更新事件。一旦设备距离之前的通知移动 500 米或更多,应用程序就会收到通知。

\n
\n\n

总而言之,startMonitoringSignificantLocationChanges仅当位置发生显着变化(大约 500 米左右)或在某个固定时间(例如 5 分钟)后,才会为您提供位置。其中将根据属性集startUpdatingLocation为您提供位置。默认distanceFilter值为distanceFilterkCLDistanceFilterNone报告所有运动。

\n\n
\n

startUpdatingLocation 立即返回。调用此方法会导致位置管理器获取初始位置修复(可能需要几秒钟)并通过调用其 locationManager:didUpdateLocations: 方法来通知您的委托。之后,接收器主要在超过 distanceFilter 属性中的值时生成更新事件。但在其他情况下可能会提供更新。例如,如果硬件收集到更准确的位置读数,接收器可以发送另一个通知。

\n
\n