What You Should Know about MKMapView for Your iOS App - dummies

What You Should Know about MKMapView for Your iOS App

By Neal Goldstein, Dave Wilson

The essence of mapping in iOS is the MKMapView. It’s a UIView subclass, you can use it out of the box to create a map. You use this class as is to display map information and to manipulate the map contents from your application.

It enables you to center the map on a given coordinate, specify the size of the area you want to display, and annotate the map with custom information (by becoming a Map View delegate).

When you initialize a Map view, you can specify the initial region for that map to display. You do this by setting the region property. A region is defined by a center point and a horizontal and vertical distance, referred to as the span. The span defines how much of the map will be visible and determines the zoom level. The smaller the span, the greater the zoom.

The Map view supports these standard map gestures:

  • Scroll

  • Pinch (to zoom)

  • Double-tap (to zoom in)

  • Two-finger tap (to zoom out)

In addition, for 3D Flyover maps you can use two-finger gestures to change the viewing angle. You can also specify the Map type — regular, satellite, or hybrid — by changing a single property.

Because MapKit.framework was written from scratch, it was developed with the limitations of the iPhone (and later the iPad) in mind. As a result, it optimizes performance on iOS devices by caching data as well as managing memory and seamlessly handling connectivity changes (such as moving from a cellular network to Wi-Fi, for example).

The map data itself is network-hosted, so network connectivity is required.

Although you shouldn’t subclass the MKMapView class itself, you can tailor a Map view’s behavior by providing a delegate object. The delegate object can be any object in your application, as long as it conforms to the MKMapViewDelegate protocol.