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.
Step 2
Create a New XCode Project by clicking on it.
Step 3
Now Select Single View Application and click on Next.
Step 4
Now provide your Product Name and Company Identifier.
Step 5
Select the location where you want to save your project and click on Create.
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.
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.
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;
}
Step 11
Click on the run button to show the output.
Output in iPhone
Output in iPad