In this recipe, you will learn how to draw polygons on the map. We will create an app that allows the user to click on the map to add a point to a preexisting polygon.
Perform the following steps:
Open the
Chapter6-Recipe7-Begin
folder and then the.xcworkspace
file. The project contains the usual Mapbox GL map already set up in the storyboard. Additionally, I addedUITapGestureRecognizer
and connected it to the following:- (IBAction)tapgestureRecognizerTapped:(id)sender
When the gesture recognizer is tapped, it will trigger the action.
First, we need to create a basic polygon and add it to the map. We will do this in a new function, as follows:
- (void)drawInitialPolygon { CLLocationCoordinate2D coordinates[] = { CLLocationCoordinate2DMake(53.359016, -6.261907), CLLocationCoordinate2DMake(53.355994, -6.265082), CLLocationCoordinate2DMake(53.352510, -6.261392) }; NSUInteger count = sizeof(coordinates) / sizeof(CLLocationCoordinate2D...