If you have an NSArray
of objects containing coordinates, it will be easier to use the polygonWithCoordinates:count:
method instead of polygonWithPoints:count:
.
The polygonWithCoordinates:count:
method accepts a C array of CLLocationCoordinate2D
structs. The coordinate
property in a CLLocation
object is also a CLLocationCoordinate2D
.
If you still want to use polygonWithPoints:count:
, you can use the MKMapPointForCoordinate
function to convert the coordinate
property in the CLLocation
to an MKMapPoint
.
With either method, you first create a C array of the appropriate struct, loop through the NSArray
to set each item in the C array. Then call polygonWithCoordinates
or polygonWithPoints
.
This answer has a code example using polygonWithCoordinates
. In that example, you would change the two lines in the for
loop to:
CLLocation *coordObj = (CLLocation *)[coordinateData objectAtIndex:i];
coords[i] = coordObj.coordinate;
Don't forget to implement the viewForOverlay
delegate method (and make sure the map view's delegate
property is set).