2011-12-31 9 views
0

私はあまりピンを必要としません、それらは領域を混雑させています。私は2つのポイント間のルートを描くためにkmlパーサの出力を使用しました。どのようにしてルート間の余分なピンを削除できますか?私は初めと終わりのためのピンだけが必要です。どのように私はKMLからそれらの過剰な赤のピン\を減らすのですか?GoogleマップのKMLファイルから注釈用の赤いピンが多すぎます

// Locate the path to the route.kml file in the application's bundle 
    // and parse it with the KMLParser. 
    kml = [[KMLParser parseKMLAtPath:filePath] retain]; 

    // Add all of the MKOverlay objects parsed from the KML file to the map. 
    NSArray *overlays = [kml overlays]; 
    [map addOverlays:overlays]; 

    // Add all of the MKAnnotation objects parsed from the KML file to the map. 
    NSArray *annotations = [kml points]; 
    [map addAnnotations:annotations]; 

    // Walk the list of overlays and annotations and create a MKMapRect that 
    // bounds all of them and store it into flyTo. 
    MKMapRect flyTo = MKMapRectNull; 
    for (id <MKOverlay> overlay in overlays) { 
     if (MKMapRectIsNull(flyTo)) { 
      flyTo = [overlay boundingMapRect]; 
     } else { 
      flyTo = MKMapRectUnion(flyTo, [overlay boundingMapRect]); 
     } 
    }  //overlay 



    for (id <MKAnnotation> annotation in annotations) { 
     MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate); 
     MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0); 
     if (MKMapRectIsNull(flyTo)) { 
      flyTo = pointRect; 
     } else { 
      flyTo = MKMapRectUnion(flyTo, pointRect); 
     } 
    }  ///annotation 


    // Position the map so that all overlays and annotations are visible on screen. 
    map.visibleMapRect = flyTo; 


    } 


    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay 
    { 
    return [kml viewForOverlay:overlay]; 
    } 

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

if ([[annotation title] isEqualToString:@"Destination"]) 
{ 
    MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenpin"]; 
    newAnnotation.pinColor = MKPinAnnotationColorGreen; 
    newAnnotation.animatesDrop = YES; 
    newAnnotation.canShowCallout = YES; 
    return newAnnotation; 


} 

else if ([[annotation title] isEqualToString:@"Current Location"]) 
{ 
    MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"yellowpin"]; 
    newAnnotation.pinColor = MKPinAnnotationColorPurple; 
    newAnnotation.animatesDrop = YES; 
    newAnnotation.canShowCallout = YES; 
    return newAnnotation; 



} 

else { 

    return [kml viewForAnnotation:annotation];} 
    } 

答えて

0

クラスタリングMKAnnotationオブジェクトのための好みのデザインパターンを示しており、「MapKitで地理的情報の可視化」、アップルのWWDC 2011のビデオにこのlinkをチェックしてください。

1

[kml ponits]のすべての注釈がマップに追加されています。

NSArray *annotations = [kml points]; 
    [map addAnnotations:annotations]; 

あなただけの最初と最後の注釈をしたいならば、単に

NSArray *annotations = [kml points]; 
    [map addAnnotation:[annotations lastObject]]; 
    [map addAnnotation:[annotations objectAtIndex:0]]; 
を追加
関連する問題