Reputation: 109
I want to create multiple annotations with different images. To create the annotations, in viewDidLoad:
for (int i=0; i<[annotationsArray count]; i++) {
RMAnnotation *annotation = [[RMAnnotation alloc]
initWithMapView:mapView
coordinate:CLLocationCoordinate2DMake([[latitudeArray objectAtIndex:i] doubleValue], [[longitudeArray objectAtIndex:i] doubleValue])
andTitle:[nameArray objectAtIndex:i]];
[self.mapView addAnnotation:annotation];
}
In the method below, it gives every annotation the same image:
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
if (annotation.isUserLocationAnnotation) {
return nil;
}
RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"CoffeeShopsIcon.png"]];
marker.canShowCallout = YES;
marker.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CoffeeShopsIcon.png"]];
marker.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return marker;
}
I have an array that holds the image names. How can I achieve this issue?
Upvotes: 1
Views: 455
Reputation: 5128
You want to use the -[RMAnnotation userInfo]
API.
/** Storage for arbitrary data. */ @property (nonatomic, strong) id userInfo;
Upvotes: 1
Reputation: 2562
You could setup a property on your RMAnnotation that denotes which image to use and then create your marker based on this property for each annotation.
Upvotes: 0