My app currently enables the user to tap anywhere and get a marker drawn there. I want a closed polygon automatically drawn when there is more than 2 markers. How do I achieve that? The first and last points should be connected to each other to create the closed shape.
My code so far that draws a polyline, but does not close it as a polygon:
// polyline setup -> array made of clicked coordinates
[latitudeTappedCoordinates addObject:[NSNumber numberWithFloat:coordinate.latitude]];
[longitudeTappedCoordinates addObject:[NSNumber numberWithFloat:coordinate.longitude]];
GMSMutablePath *rect = [GMSMutablePath path];
CLLocationCoordinate2D event;
for (int i = 0; i <= [longitudeTappedCoordinates count]-1; i++) {
event.latitude = [[latitudeTappedCoordinates objectAtIndex:i] floatValue];
event.longitude = [[longitudeTappedCoordinates objectAtIndex:i] floatValue];
[rect addCoordinate:event];
}
// draw polyline
GMSPolyline *polygon = [GMSPolyline polylineWithPath:rect];