I am trying to plot a MKPolygon on a MKMapView in iOS 4.0. I have an NSArray which contains custom objects that include properties for latitude/longitude. I have a code sample below:
- (void)viewDidLoad {
[super viewDidLoad];
dataController = [[DataController alloc] initWithMockData];
coordinateData = [dataController getCordData];
CLLocationCoordinate2D *coords = NULL;
NSUInteger coordsLen = 0;
/* How do we actually define an array of CLLocationCoordinate2d? */
MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coords count:coordsLen];
[mapView addOverlay: polygon];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolygonView *polygonView = [[MKPolygonView alloc] initWithPolygon: routePolygon];
NSLog(@"Attempting to add Overlay View");
return polygonView;
}
The way I understand it is that:
- I need to create the MKPolygon
- Ddd an overlay to MapView
- This will turn will trigger the creation of the MKPolygonView.
My question is how do i take my custom object contained in NSArray (coordinateData) and convert these object into an array of CLLocationCoordinate2d so that the Polygon can interpret and render? I'm not sure how CLLocationCoordinate2d is even an array? Can someone shed some clarity on this.