0

我使用 mapbox sdk 实现地图应用程序。我需要一起显示标记和路径,我四处搜索,但仍然没有得到主要想法。

到目前为止,我已经做了...

- (RMMapLayer *)mapView:(RMMapView *)aMapView layerForAnnotation:(RMAnnotation *)annotation {

RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"pin-blue.png"]];
if ([annotation isKindOfClass:[MyAnnotation class]]) {
    if ([annotation.annotationType isEqualToString:@"marker"]) {
        [marker replaceUIImage:[self imageWithImage:[UIImage imageNamed:@"ic_marker.png"] scaledToSize:CGSizeMake(32, 48)]];
        [marker setAnchorPoint:CGPointMake(0.5, 1)];
        return marker;
    } else if ([annotation.annotationType isEqualToString:@"path"]) {
        path.lineWidth = 3;
        for (int i=0; i<[myCoordinateArray count]; i++) {
            NSLog(@"my coord count : %d", [myCoordinateArray count]);
            CLLocationCoordinate2D myLoc = [[myCoordinateArray objectAtIndex:i] coordinate];
            if (i>0) {
                [path addLineToCoordinate:myLoc];
            } else {
                [path moveToCoordinate:myLoc];
            }
        }
        [path closePath];
        return path;
    }
} 
return nil;

}

//添加注解

myPin = [[MyAnnotation alloc] init];
        [myPin setMapView:mapView];

        [myPin setCoordinate:myLatLng];
        [myPin setTitle:@"Marker"];

        myPin.annotationType = @"marker";
        [mapView addAnnotation:myPin];
        [mapView setNeedsDisplay];

myPath = [[MyAnnotation alloc] init];
        [myPath setCoordinate:myLatLng];
        myPath.annotationType = @"path";
        [mapView addAnnotation:myPath];

我做错了什么,还是我错过了什么?请帮忙。提前致谢。

4

1 回答 1

0

首先,在您的第二个代码块中,您不需要调用setMapView:or setNeedsDisplay

其次,什么不起作用?该代码看起来应该可以工作并在地图上显示一个点和一个路径。

于 2013-02-19T17:55:36.450 回答