2011-02-28 36 views
1

我正在使用Mapkit,我在SDK 4.2上,我在這裏有一個奇怪的錯誤,實際上我有3個註釋類型,「blue.png」,red.png,black.png。我正在通過流量加載這些流程,並根據類型選擇這些註釋類型。加載地圖時一切正常,我有不同的註解視圖,但是當我移動時,放大或縮小注解視圖的變化,即它應該是blue.png它變成black.png。Mapkit放大和縮小時的註釋類型?

我實際上是在設備上測試它。

非常感謝你:)

+0

顯示viewForAnnotation方法。 – Anna 2011-02-28 11:47:29

回答

1

嘿轉向問題是,如果用戶平移地圖以查看其他位置,然後返回到標註標註的位置,則會調用此方法。

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

我見過很多地圖應用程序的示例代碼,這在大多數人正在使用。

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 
    if(annotationView) 
     return annotationView; 
    else 
    { 
     MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc] 
             initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease]; 
     pinView.animatesDrop=YES; 
     pinView.canShowCallout=YES; 
     pinView.draggable = YES; 
     pinView.pinColor = MKPinAnnotationColorGreen; 
     return pinView; 
    } 
    return nil; 
} 
+0

嘿感謝您的回覆羅賓:)我會嘗試解決方案。 再次感謝。 – Veer 2011-09-07 17:14:51

0

我找到了解決辦法 - 事實上,我使用的是自定義註解視圖,並具有3種DIFF類型的圖像:

溶液:

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

    AnnotationView *annotationView = nil; 

    // determine the type of annotation, and produce the correct type of annotation view for it. 
    AnnotationDetails* myAnnotation = (AnnotationDetails *)annotation; 

    if(myAnnotation.annotationType == AnnotationTypeGeo) 
    { 
// annotation for your current position 
     NSString* identifier = @"geo"; 
     AnnotationView *newAnnotationView = (AnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

     if(nil == newAnnotationView) 
     { 
      newAnnotationView = [[[AnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease]; 
     } 

     annotationView = newAnnotationView; 
    } 
    else if(myAnnotation.annotationType == AnnotationTypeMyfriends) 
    { 
     NSString* identifier = @"friends"; 
AnnotationView *newAnnotationView = (AnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

     if(nil == newAnnotationView) 
     { 
      newAnnotationView = [[[AnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease]; 
     } 

     annotationView = newAnnotationView; 
} 
}