Display a Region with Map Kit in iOS 7

Using Map Kit, the portion of the map that is displayed on the screen is referred to as the region. The region is defined by a center location and  a span of the surrounding area to be displayed. In this tutorial we will display  a portion of the city New York. 

Update: Feb 10, 2017. The rewritten version in Swift for iOS 10.2 and Xcode 8.2.1 is available here.

Open Xcode and create a new Single View Application. For product name, use iOS7DisplayRegionMapKitTutorial and then fill out the Organization Name, Company Identifier and Class Prefix fields with your customary values. Make sure only iPhone is selected in Devices.

To make use of the Map Kit features in our application we have to enable it into Xcode. Go to the projects settings, select the Capabilities tab and turn on the Map Kit switch.


Go to the Storyboard and drag a Map View  to the main View. Give the Map View the same size as its parent view. The StoryBoard should look like this.

Select the Assistant Editor and open ViewController.m. Ctrl and drag from the Map View  to the @interface section and create the following outlet

In ViewController.m add the Map Kit header file

#import <MapKit/MapKit.h>

In this tutorial we will show the region of New York. Define the latitude and longtitude of New York in 2 constants

#define NY_LATITUDE 40.714353
#define NY_LONGTITUDE -74.005973

In viewDidLoad add the following line

[self gotoLocation];

Next, implement the gotoLocation method.

- (void)gotoLocation
MKCoordinateRegion newRegion;

newRegion.center.latitude = NY_LATITUDE;
newRegion.center.longitude = NY_LONGTITUDE;

newRegion.span.latitudeDelta = 0.5f;
newRegion.span.longitudeDelta = 0.5f;

[self.myMapView setRegion:newRegion animated:YES];

We set our center point to the New York's coordinates and set the span settings at 0.5. Next we set our region by calling the setRegion:animated method. Build and Run, and you should see a region of New York on the screen.

You can download the source code of the iOS7DisplayRegionMapKitTutorial at the ioscreator repository on github.