2017-05-23 39 views
0

我正在使用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

回答

0

這可能是從這個重複: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