MapView and Annotation in iOS

In Xcode 6.3, go to File\New\New Project, select iOS\Application\Single View Application, and click Next.

Add New Project

On the Choose option for your new project screen,  Fill the all information about your project and click Next.

Choose your project

Save Your Project.

Click on Main.storyboard to bring up Interface Builder.


From the Object library, Select MapKit View and drag to the screen and fit as you want.

Mapkit View

Add the MapKit framework to your project, In Xcode 6.3, click on the name of your project, in General Tab, Go bottom of the screen. Locate Linked Frameworks and Libraries, click + button below.

Locate Framework and Libraries

In the “Choose Framework and Libraries” popup, typeMapKit, Select MapKit.Framework and click on add.

Add MapKit Framework

Click on Assistant Editor Button, then click on the Map Screen and hold control key and drag it to .h file and Set IBoutlet.

Assistant Editor


Go to ViewController.h file and import <MapKit/MapKit.h>

Import MapKit

Run the project. You will see map on the device.

Run on Simulator

Open ViewController.m, and add the following underneath the #imports and before the @implementation:

#define METERS_PER_MILE 1609.344


Now synthesize the mapView in ViewController.m file.

@synthesize mapView;

Now implement viewWillAppear ,

- (void)viewWillAppear:(BOOL)animated {  
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 28.632464;
    zoomLocation.longitude= 77.221023;
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
    [mapView setRegion:viewRegion animated:YES];

Run your Project again, you will find your entered location on map with zoom.

Map Run on simulator

Now Drop Pin on the Map

Add the below code in the viewWillAppear Method.

MKPointAnnotation *point= [[MKPointAnnotation alloc]init];
point.coordinate = zoomLocation;
point.title = @"Where i am?";
point.subtitle = @"I am Here!!";
[self.mapView addAnnotation:point];

Run the Project, you will find pin on the map.

Map Annotation in iOS

That’s It.

If you like this post, Please comment below or subscribe this blog.

Leave your comments


4 thoughts on “MapView and Annotation in iOS

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s