This sample code project demonstrates how to display a map with custom annotations, each with a customized callout provided by its MKAnnotationView. In addition, the Map Callouts sample project shows how you can extend annotations with custom views, strings, and callout accessory views using MKAnnotation and MKAnnotationView.
Provide an Annotation
Annotations offer a way to highlight specific coordinates on a map and provide additional information. You can use annotations to call out addresses, points of interest, and particular destinations.
To display an annotation on a map, your app must provide two distinct objects: an annotation object and an annotation view.
An annotation object conforms to the MKAnnotation protocol and manages the data for the annotation, such as the coordinate, title, and subtitle properties as shown in this section of the sample code.
Derived from the MKAnnotationView class, an annotation view draws the visual representation of the annotation on the map surface. Register annotation views with the MKMapView so the map view can create and efficiently reuse them. Use a default annotation view if you need to customize the content with a callout, or change the default marker. Use a custom annotation view if you want to have a completely custom view appear for the annotation.
When an annotation comes into view, the map view asks the MKMapViewDelegate to provide the appropriate annotation view.
Before returning from the delegate call providing the annotation view, you configure the annotation view with any customizations required for the annotation. For example, use a flag icon for an annotation view representing San Francisco.
A callout is a standard or custom view that can appear with an annotation view. A standard callout displays the annotation’s title, and it can display additional content such as a subtitle, images, and a control.
A callout can be customized in multiple ways. To place a disclosure button inside a callout: