Kan ik een MKAnnotation, of is het alleen-lezen? Ik heb coördinaten, maar ik ben het niet vinden het gemakkelijk om handmatig een MKAnnotationmet het gebruik setCoordinate.
Ideeën?
Kan ik een MKAnnotation, of is het alleen-lezen? Ik heb coördinaten, maar ik ben het niet vinden het gemakkelijk om handmatig een MKAnnotationmet het gebruik setCoordinate.
Ideeën?
MKAnnotation is een protocol. Dus je moet je eigen annotatie object dat dit protocol implementeert schrijven. Dus je MyAnnotation header er uit ziet:
@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;
en uw implementatie eruit ziet (MyAnnotation.m):
- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
coordinate = coord;
return self;
}
Dus om je annotatie toe te voegen aan de map:
MyAnnotation * annotation = [[[MyAnnotation alloc] initWithCoordinate:coordinate] autorelease];
[self.mapView addAnnotation:annotation];
Als u een titel en ondertitel van de annotatie-callout wan't, moet u de titel en ondertitel eigenschappen toe te voegen.
In iPhone OS 4 is er een nieuwe klasse MKPointAnnotation dat is een concrete uitvoering van de MKAnnotation protocol.
Controleer appel MapCallouts project. Alles wat je nodig hebt is in dat bestand: http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html