0

I want to create a custom annotation and callout on MKMapView. I have to create annotations with bigger in size and have to display three or four lines of text(labels). So how to create a custom annotation and callout bubble.

Thanks in advance.

Ashish

ashishraval
  • 53
  • 1
  • 6
  • Can you post some code showing what you have tried so far? –  May 25 '12 at 08:48
  • I have used a technique similar to the one used in this post: http://stackoverflow.com/questions/2342070/how-to-add-more-details-in-mkannotation-in-ios – brendan May 25 '12 at 19:20

2 Answers2

1

You should reimplement just 3 methods:

to customise your annotation use:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation

here just add subview which you need

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

here just delete your custom callOutView from superView

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view

Check this blog for details

Nikolay Shubenkov
  • 3,133
  • 1
  • 29
  • 31
-2

You can use this.

- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
    MKAnnotationView *a = [ [ MKAnnotationView alloc ] initWithAnnotation:newAnnotation reuseIdentifier:@"PinView"];

    if ( a == nil )
        a = [ [ MKAnnotationView alloc ] initWithAnnotation:newAnnotation reuseIdentifier: @"PinView" ];

    a.image = [ UIImage imageNamed:@"Image.png" ];
    a.canShowCallout = YES;
    a.rightCalloutAccessoryView = [ UIButton buttonWithType:UIButtonTypeDetailDisclosure ];
    UIImageView *imgView = [ [ UIImageView alloc ] initWithImage:[ UIImage imageNamed:@"Image.png" ] ];
    a.leftCalloutAccessoryView = imgView;

    return a;
}
Jake1164
  • 12,291
  • 6
  • 47
  • 64