how to add custom callout view in mapview

Mahesh Babu picture Mahesh Babu · May 1, 2012 · Viewed 7k times · Source

I am new to mapkit in objective-c. I am able to add custom annotation in mapview.

i need to place custom callout view like below image

like this.

But i didn't get how can i design callout view like this.

i know i need to add callout in view for annotation method.

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }

    annotationView.image = [UIImage imageNamed:@"blue_without_pin.png"];
    annotationView.annotation = annotation;


    return annotationView;
}

Answer

PatrickNLT picture PatrickNLT · Jun 5, 2012

Basically what you want to do is add a new custom view by implementing the following method in your MKMapViewDelegate instance :

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    CGPoint annotationCenter = [mapView convertCoordinate:view.annotation.coordinate toPointToView:mapView];
    [self displayCustomCalloutForAnnotation:view.annotation center:annotationCenter];
}