James Frempong
James Frempong

Reputation: 31

Array of Map Annotation

How do i create an array of annotations in mapview for Xcode? I hav tried NSMutableArray *ann = [NSMutableArray alloc]init];

the annotation

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

I have 57 of these how do i put them in an array.

Upvotes: 0

Views: 990

Answers (1)

The dude
The dude

Reputation: 7924

send the message addObject to NSMutableArray.

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

Another option is to init the array with objects:

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

You can then add the anotations to the mapview all at once:

[mapview addAnnotations:annotationArray];

Upvotes: 2

Related Questions