You need to create a delegate that implements the MKAnnotation protocol:
@interface AnnotationDelegate : NSObject <MKAnnotation> { CLLocationCoordinate2D coordinate; } @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; - (id) initWithCoordinate:(CLLocationCoordinate2D)coord; @end @implementation AnnotationDelegate @synthesize coordinate; - (id) initWithCoordinate:(CLLocationCoordinate2D)coord { coordinate.latitude = coord.latitude; coordinate.longitude = coord.longitude; return self; } @end
For each of your map points, you need to create an instance of one of the AnnotionDelegate objects (passing in the coordinates of the point) and add it to MKMapView:
AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] initWithCoordinate:coordinate] autorelease]; [self._mapView addAnnotation:annotationDelegate];
source share