3

i have one view >> subview mkmapview .

in that i want to show image . ...my current image is like this.alt text

and i want to show like this

alt text

how can i do this ? how can i add image in this anotation.

3 Answers 3

7

The image you're talking about corresponds to the leftCalloutAccessoryView property of MKAnnotationView.

Extract from the doc :

leftCalloutAccessoryView The view to display on the left side of the standard callout bubble.

You can implement a methods such as this :

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation { MKAnnotationView* annotationView = nil; MyAnnotation *myAnnotation = (MyAnnotation*) annotation; NSString* identifier = @"Pin"; MKPinAnnotationView* annView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if(nil == annView) { annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease]; } UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LeftIconImage.png"]]; annView.leftCalloutAccessoryView = leftIconView; return annotationView; } 

Hope this helps, Vincent

Sign up to request clarification or add additional context in comments.

1 Comment

Last line should change to 'return annView;' instead.
3

In your MKAnnotationView set the leftCalloutAccessoryView property

leftCalloutAccessoryView The view to display on the left side of the standard callout bubble.

@property (retain, nonatomic) UIView *leftCalloutAccessoryView Discussion The default value of this property is nil. The left callout view is typically used to display information about the annotation or to link to custom information provided by your application. The height of your view should be 32 pixels or less.

If the view you specify is also a descendant of the UIControl class, you can use the map view’s delegate to receive notifications when your control is tapped. If it does not descend from UIControl, your view is responsible for handling any touch events within its bounds.

Availability Available in iOS 3.0 and later. See Also @property canShowCallout Related Sample Code MapCallouts Declared In MKAnnotationView.h

Apple docs

Comments

-1
v.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]]; 

where v - is the view of your annotation(MKAnnotationView) Or if you want complete solution - here it is:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ NSString *Identifier = [NSString stringWithFormat:@"%f%f",annotation.coordinate.latitude,annotation.coordinate.longitude]; MKPinAnnotationView *annView= (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:Identifier]; if (annView==nil) { annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:Identifier] autorelease]; } if (![annotation isKindOfClass:[MyAnnotation class]]) { return nil; } RightCalloutAccessoryBtn* rightButton = [RightCalloutAccessoryBtn buttonWithType:UIButtonTypeDetailDisclosure]; annView.rightCalloutAccessoryView = rightButton; annView.leftCalloutAccessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]] autorelease]; annView.canShowCallout = YES; return annView; } 

You should write this code on the class of your map's delegate

3 Comments

You are assigning a UIImage* to a UIView* property. I don't think that's going to work. Try [[UIImageView alloc] initWithImage:...].
Adding a UIImage* to UIView* won't work. Try UIImageView* instead.
Of course, UIImageView, you are right guys. It was just mistake and this answer is so old I forgot about it (almost 5 years and even with manual reference counting code). Fixed my answer according to your comments