Get location updates in a power-friendly way, but less frequently than with the standard location service.
- Core Location
The significant-change location service offers a more power-friendly alternative for apps that need location data but don't need frequent updates or the precision of GPS. The service relies on lower-power alternatives (such as Wi-Fi and cellular information) to determine the user’s location. It then delivers location updates to your app only when the user’s position changes by a significant amount, such as 500 meters or more.
To start the significant-change location service, call the
start method of your location manager. With this service, the location manager ignores the values in its
desired properties, so you don't need to configure them. The location manager delivers updates to the
location method of its delegate. Listing 1 shows how to check for the availability of the significant-change location service and start it.
Another way to save power is to set the
pauses property of your location manager object to true. Enabling this property lets the system reduce power consumption by disabling location hardware when the user is unlikely to be moving. Pausing updates doesn't diminish the quality of those updates, but can improve battery life significantly. To help the system determine when to pause updates, you must also assign an appropriate value to the
activity property of your location manager.
Receiving Location Updates
When you start the significant-change location service, a recently cached value may be reported to your delegate immediately. As new location data is obtained, the location manager calls your delegate's
location method with the updated values. The
locations parameter always contains at least one location and may contain more than one. Locations are always reported in the order in which they were determined, so the most recent location is always the last item in the array, as shown in Listing 2.
Before using a location value, check the time stamp of the
CLLocation object. Because the system may return cached locations, checking the time stamp lets you know whether to update your interface right away or perhaps wait for a new location.
Handling Location-Related Errors
When the location manager is unable to deliver location updates, it calls the
location method of its delegate object. You should always implement this delegate method to handle any errors that might occur. For example, this method is called when the user denies authorization for your app to use location services. In such a scenario, you might want to disable location-related features and notify the user which features are unavailable. You should also stop whatever service you previously started, as demonstrated in Listing 3.