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?
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.
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.
© 2022 - 2024 — McMap. All rights reserved.