What is difference between startMonitoringSignificantLocationChanges() and startUpdatingLocation() method of CLLocationManager?
Asked Answered
A

2

6

I'm working with CLLocationManager class. I want to get location updates periodically. I had found two methods to get location in didUpdateLocations method, that are startUpdatingLocation() and startMonitoringSignificantLocationChanges(). If I have to track location updates in foreground mode also then which method should I use?

Arrowwood answered 9/2, 2016 at 6:54 Comment(2)
Possible duplicate of How do startMonitoringSignificantLocationChanges and startUpdatingLocation effect one-another?Oralla
FYI this answer says: "My iPhone 5s drains the battery only 1% over night with the significant location changes active, instead of 12% with having the standard location updates active with the accuracy set to 3km."Orms
V
6

The most important difference between the 2 is this:

startMonitoringSignificantLocationChanges: it does not rely on the value in the distanceFilter property to generate events. The receiver generates update events only when a significant change in the user’s location is detected

startUpdatingLocation : the receiver generates update events primarily when the value in the distanceFilter property is exceeded

So, if you want more precision, go for startUpdatingLocation, at the expense of more battery consumption, but more precision of the location. It really depends on your goal, you should evaluate the tradeoff.

Vaporize answered 9/2, 2016 at 7:15 Comment(0)
Y
4

startMonitoringSignificantLocationChanges initiates the delivery of location events asynchronously, returning shortly after you call it. Location events are delivered to your delegate’s locationManager:didUpdateLocations: method. The first event to be delivered is usually the most recently cached location event (if any) but may be a newer event in some circumstances. After returning a current location fix, the receiver generates update events only when a significant change in the user’s location is detected. Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification.

To sum up startMonitoringSignificantLocationChanges will provide you with location only when location changes by some significant amount which is roughly around 500 meters or after some fixed time say 5 minutes. Where as startUpdatingLocation will provide you with location based on distanceFilter property set. Default value of distanceFilter is kCLDistanceFilterNone which reports all the movements.

startUpdatingLocation returns immediately. Calling this method causes the location manager to obtain an initial location fix (which may take several seconds) and notify your delegate by calling its locationManager:didUpdateLocations: method. After that, the receiver generates update events primarily when the value in the distanceFilter property is exceeded. Updates may be delivered in other situations though. For example, the receiver may send another notification if the hardware gathers a more accurate location reading.

Yonatan answered 9/2, 2016 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.