Kann ich ein schaffen MKAnnotationnur, oder ist es gelesen? Ich habe Koordinaten, aber ich finde es nicht leicht manuell erstellen eine MKAnnotationmit der Verwendung setCoordinate.
Ideen?
Kann ich ein schaffen MKAnnotationnur, oder ist es gelesen? Ich habe Koordinaten, aber ich finde es nicht leicht manuell erstellen eine MKAnnotationmit der Verwendung setCoordinate.
Ideen?
MKAnnotation ist ein Protokoll. So müssen Sie Ihre eigene Anmerkung Objekt schreibendie dieses Protokoll implementiert. Also Ihre MyAnnotation Header wie folgt aussehen:
@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;
und Ihre Implementierung sieht aus wie (MyAnnotation.m):
- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
coordinate = coord;
return self;
}
So Ihre Anmerkung zu der Karte hinzuzufügen:
MyAnnotation * annotation = [[[MyAnnotation alloc] initWithCoordinate:coordinate] autorelease];
[self.mapView addAnnotation:annotation];
Wenn Sie einen Titel und Untertitel auf der Anmerkung callout wan't, müssen Sie den Titel und Untertitel-Eigenschaften hinzuzufügen.
In iPhone OS 4 gibt es eine neue Klasse MKPointAnnotation, die eine konkrete Umsetzung des MKAnnotation Protokolls ist.
Überprüfen Apfel MapCallouts Projekt. Alles , was Sie brauchen , ist in dieser Datei: http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html