O'Reilly logo

Learning iPhone Programming by Alasdair Allan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Geolocation and Mapping

The Core Location API is one of the great things about the iPhone and iPod touch platforms, but until the arrival of the MapKit Framework in the 3.0 SDK, it was actually quite hard to take that location-aware goodness and display it on a map. The arrival of the MapKit framework has simplified this enormously.

Let’s work through a few example applications to get you familiar with the framework.

User Location

Note

You can follow along while I build this application in a screencast available on the book’s website.

The first thing we’re going to do is build a simple application to answer the question “Where am I?”. Start a new iPhone project in Xcode, select a view-based template, and name the project “WhereAmI” when prompted.

Next, you need to add the MapKit and Core Location frameworks to your new project. You do not need the Core Location framework to work with MapKit, but we’re going to use it later in the chapter, so we may as well add it now:

  1. Right-click on the Frameworks group in the Groups & Files pane in Xcode and select AddExisting Frameworks. In the pop-up window that appears, select the MapKit framework and click Add.

  2. Do this a second time, but for the Core Location framework.

Warning

If you have upgraded your Xcode (and iPhone SDK) distribution in the middle of developing a project, MapKit.framework may not show up in the list of frameworks Xcode presents in the framework selection pop up. In this case, you may be able to resolve the problem by ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required