Search code examples
iphonegoogle-mapsios4mapkit

HowTo detect tap on map annotaition Pin?


I want to detect tap on annotation pin(of mapkit) so that I can perform action on that event.

Now the default annotation flag pops up in case I touch the annotation pin. I want to customise that to call my method when pin is touched.


Solution


  • You need to implement the following delegate method

     (MKAnnotationView) mapView viewForAnnotation:(id) annotation  
    

    Then just declare following in this method

    MKPinAnnotationView *view=[[MKPinAnnotationView alloc]initWithAnnotation:annotation  reuseIdentifier:@"abc"];
    view.canShowCallout=YES;
    view.calloutOffset=CGPointMake(-20,10); //As per your choice
    

    Then you can add UI to your callout eg UIButton or UIImage as view.rightCalloutAccesoryView View.leftCalloutAccesoryView