2017-05-23 4 views
0

私は、long 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

これはおそらく、このことから重複している:あなたはMKOverlayを追加するのiOS 7.0以降、以来そこに示唆したようにHow do I show MKOverlay above MKAnnotations?

マップにはaddOverlay:level:メソッドを使用します。これにより、オーバーレイのz位置を指定することができます。 MKOverlayLevelsによって定義されるオーバーレイの最高z位置の一つはMKOverlayLevelAboveLabels:

プレースマップラベル、シールド、またはポイントオブ関心 アイコン上記なく注釈や建物の3D投影下オーバーレイです。

+0

こんにちは@返信ありがとうございますが、上記のリンクは私が欲しいものの逆です。実際に注釈ピンがポリラインの上に正しく表示されていますが、ポリラインがツリーの下を通過するいくつかの場所では、飛び越えて、注釈ピンもこれらの下を通過する必要があります。 – VIVEK

+0

私が理解するところでは、あなたの 'MKPolyline'の垂直レベルはOKではありません。なぜレベルを変えてみませんか? – pesch

+0

あなたはレベルをMKOverlayLevelAboveLabelsに変更することを意味しますか?しかし、これは、ポリラインがまだ木と橋の下にあるのでどちらかを助けるものではありません。 – VIVEK

関連する問題