In Xcode 6.3, go to File\New\New Project, select iOS\Application\Single View Application, and click Next.
On the Choose option for your new project screen, Fill the all information about your project and click Next.
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.
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.
In the “Choose Framework and Libraries” popup, typeMapKit, Select MapKit.Framework and click on add.
Click on Assistant Editor Button, then click on the Map Screen and hold control key and drag it to .h file and Set IBoutlet.
Go to ViewController.h file and import <MapKit/MapKit.h>
Run the project. You will see map on the device.
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.
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.
That’s It.
If you like this post, Please comment below or subscribe this blog.