MKAnnotation is a protocol. So you need to write your own annotation object that implements this protocol. So your MyAnnotation header looks like:
@interface MyAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
// add an init method so you can set the coordinate property on startup
- (id) initWithCoordinate:(CLLocationCoordinate2D)coord;
and your implementation looks like (MyAnnotation.m):
- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
coordinate = coord;
return self;
}
So to add your annotation to the map:
MyAnnotation * annotation = [[[MyAnnotation alloc] initWithCoordinate:coordinate] autorelease];
[self.mapView addAnnotation:annotation];
If you wan't a title and subtitle on the annotation callout, you need to add the title and subtitle properties.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…