Chapter 34. Maps

Your app can imitate the Maps app, communicating with Google Maps to present a map interface and placing annotations and overlays on the map. UIView subclasses for displaying the map, along with the programming API, are provided by the Map Kit framework. You’ll link to MapKit.framework and import <MapKit/MapKit.h>. You might also need the Core Location framework to express locations by latitude and longitude; you’ll link to CoreLocation.framework and import <CoreLocation/CoreLocation.h>.

Presenting a Map

A map is presented through a UIView subclass, an MKMapView. The map is potentially a map of the entire world; the map view is usually configured to display a particular area. An MKMapView instance can be created in code or through the nib editor. A map has a type, which is one of the following:

  • MKMapTypeStandard
  • MKMapTypeSatellite
  • MKMapTypeHybrid

The area displayed on the map is its region, an MKCoordinateRegion. This is a struct comprising a location (a CLLocationCoordinate2D), describing the latitude and longitude of the point at the center of the region, along with a span (an MKCoordinateSpan), describing the quantity of latitude and longitude embraced by the region. Convenience functions help you construct an MKCoordinateRegion.

In this example, I’ll initialize the display of an MKMapView to show a place where I like to go dirt biking. The MKMapView is placed into the interface through the nib editor and is initially hidden so that the user doesn’t see the default ...

Get Programming iOS 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.