Chapter 34

Where Am I? Introducing Core Location

Core Location is a framework that allows applications to retrieve the location and heading of the device they are running on. To do this, Core Location can use a combination of a compass for heading, and either GPS, cellular radio, or WiFi technologies for location. Cellular radio and WiFi-based location is less accurate than GPS.

Applications cannot specify which method will be used; however, they can specify a desired level of accuracy. Depending on the desired level of accuracy, Core Location tries to use the GPS hardware, cellular radio, or WiFi in that order.

This framework is not included in any of the standard iOS application templates. To use this framework in your code you will need to add it manually to your project. You can do this from the Project Settings page in Xcode. Select the project node in the project navigator to display the settings page. On the settings page, switch to the Build Phases tab and click the + button under the Link Binary With Libraries category. Select CoreLocation.framework from the list of available frameworks (Figure 34-1).

Core Location defines a manager class called CLLocationManager that you can use to interact with the framework. It allows you to specify the desired frequency and accuracy of location information. To receive location updates in an application, you need to create an instance of the CLLocationManager class, and provide a delegate object to receive location updates and errors. ...

Get iPhone and iPad App 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.