Is there a simple example project for MKAnnotation
? I don\'t know what to pass at \"addAnnotation
\", as it wants some \"id
You need to have a class implementing the MKAnnotation
protocol. Here is a snippet from one of my projects:
@interface MapPin : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) NSString *subtitle;
- (id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:(NSString *)placeName description:(NSString *)description;
@end
Then, where you create the map you'll call:
pin = [[MapPin alloc] initWithCoordinates:[track startCoordinates] placeName:@"Start" description:@""];
[map addAnnotation:pin];
EDIT:
Here is the implementation:
@implementation MapPin
@synthesize coordinate;
@synthesize title;
@synthesize subtitle;
- (id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:placeName description:description {
self = [super init];
if (self != nil) {
coordinate = location;
title = placeName;
[title retain];
subtitle = description;
[subtitle retain];
}
return self;
}
- (void)dealloc {
[title release];
[subtitle release];
[super dealloc];
}
@end
Hope this helps, Onno.