Chapter 8. Getting a Fix: Core Location

The Core Location framework provides access to the iPhone's geographical location systems. These include an integrated GPS, WiFi-based location positioning, and tower triangulation. The iPhone is a very location-aware device, and even stores the GPS coordinates to nearby towers in its cache. Using the Core Location framework, you're able to obtain the device's longitude and latitude coordinates, altitude, and other important data. Core Location uses a type of streaming notification so that your application receives updates as the GPS ascertains a more accurate fix.

Apple added a basic level of security to the Core Location interface, and when your application attempts to use it, the user will be prompted whether to allow it access to his current location. If the user restricts your application from using Core Location, you'll need to be prepared to deliver any remaining portions of your application's functionality without this information, or prompt the user for a zip code or other information. In addition to a user prompt, Apple has incorporated a Core Location blacklist into the iPhone's firmware. The iPhone will query this list on Apple's servers whenever it performs a lookup, and will kill any applications that have been blacklisted.

The process of performing a location lookup is relatively power-intensive, as it queries GPS satellites, local towers, and WiFi hotspots, so be conservative in your use of Core Location to avoid draining the user's battery.

To use the Core Location framework, you'll need to add it to your Xcode project. Right-click the Frameworks folder in your project, and then choose Addrightwards double arrowExisting Framework. Navigate to the CoreLocation.framework folder, and then click Add.

At the time of this writing, applications providing turn-by-turn directions or aviation-based navigation tools are restricted, by policy, from the AppStore. Be sure to check your agreements with Apple to ensure that its use of this information does not violate their terms.