有多个引脚注释? MapKit
问题描述:
此刻我有1个针脚,当您点击该针脚时,它会显示信息。不过,我想要在不同位置使用1个以上的引脚。我将如何做到这一点?有多个引脚注释? MapKit
这是我的代码。
Map.m
- (void)viewDidLoad
{
[super viewDidLoad];
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = 52.509078;
region.center.longitude = -1.884799;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];
NewClass *ann = [[NewClass alloc] init];
ann.title = @"AVFC";
ann.subtitle = @"Aston Villa Football Club";
ann.coordinate = region.center;
[mapview addAnnotation:ann];
// Do any additional setup after loading the view, typically from a nib.
}
NewClass.h
@interface NewClass : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *titleOne;
NSString *subtitleTwo;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *titleOne;
@property (nonatomic, copy) NSString *subtitleTwo;
@end
答
创建您的注释(但很多你想要的)然后将它们添加到NSArray
。您可以使用[mapview addAnnotations:annotationArray];
+0
我该如何在代码中做到这一点?谢谢 – 2012-03-09 23:31:29
+0
你对哪个部分感到困惑? – bschultz 2012-03-09 23:34:46
尝试在这里考虑看看它们添加到您的
MKMapView
,它是在开始使用MapKit,包括注释一个很好的教程:HTTP://www.raywenderlich.com/2847/introduction- to-mapkit-on-ios-tutorial – 2012-03-09 23:37:57