Mapbox注释

时间:2014-08-18 16:14:25

标签: ios mapbox

我想用不同的图像创建多个注释。要在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;
}

我有一个包含图像名称的数组。我怎样才能解决这个问题呢?

2 个答案:

答案 0 :(得分:1)

您想使用-[RMAnnotation userInfo] API。

/** Storage for arbitrary data. */
@property (nonatomic, strong) id userInfo;

答案 1 :(得分:0)

您可以在RMAnnotation上设置一个属性,表示要使用的图像,然后根据此属性为每个注释创建标记。