Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I show an image in map pin annotation?

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.


1 Answers

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

like image 74
vdaubry Avatar answered Dec 07 '25 20:12

vdaubry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!