我在 - (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation 中画了一条线。但同时我也想使用自定义标记进行注释。我怎样才能做到这一点。任何形式的帮助将不胜感激。下面是我的源代码。
-(void) drawSipTrackerPath
{
RMMapboxSource *tileSource = [[RMMapboxSource alloc] initWithMapID:@"id"];
self.mapView = [[RMMapView alloc] initWithFrame:CGRectMake(0, 64, 375, 534) andTilesource:tileSource];
self.mapView.delegate = self;
self.mapView.clusteringEnabled = YES;
[self.view addSubview:self.mapView];
self.mapView.zoom = 3;
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth;
double latitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray lastObject]valueForKey:@"lat"]] doubleValue];
double longnitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray lastObject]valueForKey:@"lon"]] doubleValue];
for(NSInteger i=0; i < self.trajectoryArray.count; i++)
{
double latitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray objectAtIndex:i]valueForKey:@"lat"]] doubleValue];
double longnitude = [[NSString stringWithFormat:@"%@",[[self.trajectoryArray objectAtIndex:i]valueForKey:@"lon"]] doubleValue];
CLLocation* location = [[CLLocation alloc]initWithLatitude:latitude longitude:longnitude];
[self.trajectoryArray replaceObjectAtIndex:i withObject:location];
}
CLLocationCoordinate2D coordinate = [self getLocationObject:latitude toLong:longnitude];
RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:self.mapView
coordinate:coordinate
andTitle:@"My Path"];
annotation.userInfo = @"My path";
[self.mapView addAnnotation:annotation];
RMPointAnnotation *annotationn = [[RMPointAnnotation alloc]
initWithMapView:self.mapView
coordinate:coordinate
andTitle:@"Hello, world!"];
annotationn.annotationIcon = [UIImage imageNamed:@"arrow"];
annotationn.userInfo = @"Hello World";
[self.mapView addAnnotation:annotationn];
[annotationn setBoundingBoxFromLocations:self.trajectoryArray];
[self.mapView setCenterCoordinate:coordinate animated:YES];
}
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
if (annotation.isUserLocationAnnotation)
return nil;
RMShape *shape = [[RMShape alloc] initWithView:mapView];
shape.lineColor = [UIColor redColor];
shape.lineWidth = 5.0;
for (CLLocation *point in self.trajectoryArray)
{
[shape addLineToCoordinate:point.coordinate];
}
return shape;
}