地图注释数组

时间:2012-08-16 10:46:41

标签: objective-c xcode4.3

如何在mapview中为Xcode创建注释数组?我试过了 NSMutableArray * ann = [NSMutableArray alloc] init];

注释

CLLocationcoordinate2D thecoordinate;
thecoordinate.latitude =92.3;
thecoordinate.longitude = 12.78;
MyAnnotationClass *ann = [MyAnnotationClass alloc];
region.coordinate = thecoordinate;
[mapview addannotation: ann];

我有57个这样的把它放在一个数组中。

1 个答案:

答案 0 :(得分:2)

将消息addObject发送到NSMutableArray。

NSMutableArray* annotationArray = [[NSMutableArray alloc] init];
[annotationArray addObject:ann]; //ann is an instance of MyAnnotationClass. Call this method for every MyAnnotationClass object you have.

另一个选择是使用对象初始化数组:

NSMutableArray* annotationArray =[NSMutableArray arrayWithObjects: arr1, arr2, arr3, arr4, nil]; //arr1,arr2... are your MyAnnotationClass objects.

然后,您可以一次性将地图集添加到地图视图中:

[mapview addAnnotations:annotationArray];