iPhone: Maak MKAnnotation

stemmen
14

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?

De vraag is gesteld op 21/05/2010 om 01:09
bron van user
In andere talen...                            


3 antwoorden

stemmen
40

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.

antwoordde op 21/05/2010 om 01:21
bron van user

stemmen
32

In iPhone OS 4 is er een nieuwe klasse MKPointAnnotation dat is een concrete uitvoering van de MKAnnotation protocol.

antwoordde op 24/06/2010 om 12:10
bron van user

stemmen
9

Controleer appel MapCallouts project. Alles wat je nodig hebt is in dat bestand: http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html

antwoordde op 03/06/2010 om 02:14
bron van user

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more