2013-06-03 78 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; 

}

它为我,试试这个