我想用不同的图像创建多个注释。要创建注释,在 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];
}
在下面的方法中,它为每个注释提供相同的图像:
- (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;
}
我有一个包含图像名称的数组。我怎样才能解决这个问题?
最佳答案
您想使用 -[RMAnnotation userInfo]
API。
/** Storage for arbitrary data. */ @property (nonatomic, strong) id userInfo;
关于ios - map 框标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25367654/