MKAnnotationview不坚持MKPolyline覆盖路线

问题描述:

我正在使用lat long值的数组添加MKPolyline。当我在多段线上绘制注解时,注解视图会在树,天桥和MKPolyline下方到达这些对象下方。有什么办法可以解决这个问题吗? 下面我试图为:MKAnnotationview不坚持MKPolyline覆盖路线

// access location array to get lat long values 

      NSInteger numberOfSteps = locations.count; 
      CLLocationCoordinate2D coordinates[numberOfSteps]; 
      for (NSInteger index = 0; index < numberOfSteps; index++) { 
       CLLocation *location = [locations objectAtIndex:index]; 
       CLLocationCoordinate2D coordinate = location.coordinate; 
       coordinates[index] = coordinate; 
      } 

     MKPolyline *polyLine = [MKPolyline  polylineWithCoordinates:coordinates count:numberOfSteps]; 
      [_routeMapView addOverlay:polyLine level:MKOverlayLevelAboveRoads]; 

//我在这里添加自定义的注释针。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{ 

    if (![annotation isKindOfClass:[CustomPointAnnotation class]]) 
     return nil; 

    NSString *reuseId = @"test"; 

    MKAnnotationView *anView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId]; 
    if (anView == nil) { 
     anView = [[MKAnnotationView alloc] initWithAnnotation:point reuseIdentifier:reuseId]; 
     anView.canShowCallout = NO; 
    } 
    else 
    { 
     anView.annotation = annotation; 
    } 

    //Set annotation-specific properties **AFTER** 
    //the view is dequeued or created... 

    CustomPointAnnotation *cpa = (CustomPointAnnotation *)annotation; 
    anView.image = [UIImage imageNamed:cpa.imageName]; 
    return anView; 
} 

// show route from source to destination 

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay 
{ 
    if ([overlay isKindOfClass:[MKPolyline class]]) 
    { 
     MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay]; 
     renderer.strokeColor = [[UIColor redColor] colorWithAlphaComponent:0.7]; 
     renderer.lineWidth = 4; 
     return renderer; 
    } 
    return nil; 
} 

这里是我有什么问题:

enter image description here

这可能是从这个重复:How do I show MKOverlay above MKAnnotations?

由于自iOS 7.0以上版本建议在那里,当你添加MKOverlay到地图上,使用addOverlay:level:方法。这允许您指定叠加层的z位置。其中最高的z轴位置的由MKOverlayLevels定义覆盖的是MKOverlayLevelAboveLabels:

将上述地图标签,盾牌,或点兴趣 图标,但低于注释和建筑物的3D投影覆盖。

+0

嗨@pesch,感谢您的回复,但上面的链接正在做我想要的相反。实际上,注释引脚在折线上方正确显示,但在折线在树下传递的某些位置处,天桥然后我希望注释引脚也应在这些下方通过。 – VIVEK

+0

据我所知,你的'MKPolyline'的垂直水平是不正确的。你为什么不尝试改变它的水平? – pesch

+0

您的意思是将其级别更改为MKOverlayLevelAboveLabels?。但是这也没有帮助,因为折线仍然在树和桥下。 – VIVEK