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.
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
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
Next, implement the gotoLocation method.
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.