A map without points of interest is less useful. In this recipe, you will learn how to generate markers, or annotations as they are called in iOS terminology.
Follow these steps:
Open the
Chapter6-Recipe4-Begin
folder and then the.xcworkspace
file in Xcode. This project contains the project as it ended in the previous recipe.The + button is already connected in the storyboard to our
viewController.m
file's following method:- (IBAction)addAnnotation:(id)sender
We first need to initialize a new annotation. We will first create a new
MGLPointAnnoation
object. Within the– (IBAction)addAnnotation:(id)sender
context, add the following line:MGLPointAnnotation *annotation = [[MGLPointAnnotation alloc] init];
The next step is to pass the coordinates; run the following command for this:
[annotation setCoordinate:self.mapView.centerCoordinate];
Here,
self.mapView.centerCoordinate
will create the annotation at the center of our map. It will always be at the center...