Map View in iPhone and iPad

Introduction

In this article I will create a Single view application. Here I use a map view from xib. Here I pass a latitude and longitude value of a particular location via code and show the output in an iPhone or iPad.  

To understand it we use the following.

Step 1

Open XCode by double-clicking on it.

Select-xcode-in-iphone.jpg

Step 2

Create a New XCode Project by clicking on it.

create-project-in-iphone.jpg

Step 3

Now Select Single View Application and click on Next.

single-view-application-in-iphone.jpg

Step 4

Now provide your Product Name and Company Identifier.

project-name-in-iPhone-iPad.jpg

Step 5

Select the location where you want to save your project and click on Create.

save-project-location-in-iphone.jpg

Step 6 

Here first add framework MkMapkit which is required to show the location.

To import this framework we use the following:

Step 7

Click on the project and select Build Phase.

build-phase-in-iPhone.jpg

Step 8

Click on the "+" icon to add the framework.

Step 9

Select the framework you want to add write on search bar and click on the add button.

add-mapkit-framework-in-iPhone.jpg

Step 10

Now we write the code and add a mapview from xib. See:


- (void)viewDidLoad
{
    [super viewDidLoad];
      map = [[MKMapView alloc]initWithFrame:self.view.bounds];
    map.delegate=self;
    
    [self.view addSubview:map];
    [NSThread detachNewThreadSelector:@selector(displaymap) toTarget:self withObject:nil];
    
}
-(void)displaymap
{
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta=0.2;
    span.longitudeDelta=0.2;
    CLLocationCoordinate2D location;
    
      location.latitude = 23.569722 ;
      location.longitude = 77.369722;
      
    
    region.span=span;
    region.center=location;
      


}
  

linking-in-iPhone.jpg

Step 11

Click on the run button to show the output.

Output in iPhone

output-in-iPhone.jpg

Output in iPad

output-in-iPad.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all