A minta alkalmazás WorldCities bemutatja, hogyan lehet nagyítani, egy adott helyen, de ez nem egy gombostűt is. Tovább Példaalkalmazás úgynevezett MapCallouts csinál csepp csapok, de nem zoom.
A zoom része könnyű (lásd didChooseWorldCity módszer WorldCities).
Gombostű, meg kell küldeni a addAnnotation üzenetet a mapview és küldje el egy objektumot, amely végrehajtja a MKAnnotation protokollt. Tehát először meg kell hozzon létre egy osztályt, amely megvalósítja MKAnnotation. Íme egy példa az úgynevezett MyMapPin:
//MyMapPin.h...
#import <MapKit/MapKit.h>
@interface MyMapPin : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *subtitle;
NSString *title;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic,retain) NSString *subtitle;
@property (nonatomic,retain) NSString *title;
- (id) initWithCoords:(CLLocationCoordinate2D) coords;
@end
//MyMapPin.m...
#import "MapPin.h"
@implementation MyMapPin
@synthesize coordinate;
@synthesize subtitle;
@synthesize title;
- (id) initWithCoords:(CLLocationCoordinate2D) coords {
self = [super init];
if (self != nil) {
coordinate = coords;
}
return self;
}
- (void) dealloc
{
[title release];
[subtitle release];
[super dealloc];
}
@end
Most már lehet módosítani a WorldCities minta hozzáadásával ezt a kódot az elején a animateToPlace módszer:
MyMapPin *pin = [[MyMapPin alloc] initWithCoords:worldCity.coordinate];
[mapView addAnnotation:pin];
[pin release];
worldCity.coordinate a WorldCities app csak egy tulajdonsága típusú CLLocationCoordinate2D amely két területen szélességi és hosszúsági. A két úszik menne oda.
Megjegyzés: a addAnnotation majd csak tesz egy pin a város. Ahhoz, hogy egy animált csepegtető csapot, akkor is végre kell hajtania a viewForAnnotation eljárás és állítsa animatesDrop YES. Lásd példaként MapViewController.m a MapCallouts. Állítsa be az mapview megbízottja, hogy ott, ahol a viewForAnnotation módszerrel hajtják végre (általában magától / fájl tulajdonosa).