2013-06-03 129 views
0

下面,我創建了一個我的地圖的註釋,它完美地工作,並顯示標題和副標題。地圖註釋添加圖片

但我希望在註釋的左側添加一個小圖像,但無法弄清我需要做些什麼才能使其工作。

// Annotation 
CLLocationCoordinate2D poseLocation; 
poseLocation.latitude = POSE_LATITUDE; 
poseLocation.longitude = POSE_LONGITUDE; 

Annotation *myAnnotation = [[Annotation alloc] init]; 
myAnnotation.coordinate = poseLocation; 
myAnnotation.title = @"Pose Beauty Salon"; 
myAnnotation.subtitle = @"100, Moneyhaw Road"; 

[self.myMapView addAnnotation:myAnnotation]; 
+2

無關,但你應該做的'[[譯註頁頭] INIT]',而不是僅僅'[譯註頁頭];'。 – Anna

回答

2

您將需要首先設置myMapView的委託並實現viewForAnnotation委託方法。

有將返回其具有屬性leftCalloutAccessoryView MKAnnotationView實例:

的視圖來顯示在標準標註氣泡的左側。 此屬性的默認值爲零。左側標註視圖爲 ,通常用於顯示有關注釋的信息或將 鏈接到應用程序提供的自定義信息。您的 視圖的高度應該爲32像素或更少。

在leftCalloutAccessoryView中,您可以在那裏指定您的圖像。例如:

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

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.myMapView dequeueReusableAnnotationViewWithIdentifier:@"annotation"]; 

    if (annotationView == nil) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"];    
     UIImageView *imageView = //initialize your image view here 
     annotationView.leftCalloutAccessoryView = imageView; 
    } 

    annotationView.annotation = annotation; 
    return annotationView; 
} 

PS:很顯然你問類似的問題之前在這裏:Add image to the left of my annotations。我不確定你需要發佈另一個問題。請先嚐試執行此操作。

0
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{ 
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"]; 

myImage = [UIImage imageNamed:imagename]; 
CGRect cropRect = CGRectMake(0.0, 0.0,35.0, 35.0); 
myImageView = [[UIImageView alloc] initWithFrame:cropRect]; 
myImageView.clipsToBounds = YES; 
myImageView.image = myImage; 
MyPin.leftCalloutAccessoryView =myImageView; 
MyPin.highlighted=YES; 
MyPin.canShowCallout=YES; 
return MyPin; 

}

它爲我,試試這個