MKMapView class supports the capability to annotate the map with custom information. The annotation has two parts: the annotation itself, which contains the data for the annotation, and the Annotation view, which displays the data.
Creating the annotation
Any object that conforms to the
MKAnnotation protocol is an Annotation object; typically, Annotation objects are existing classes in your application’s model. The job of an Annotation object is to know its location (coordinates) on the map along with the text to be displayed in the callout. The
MKAnnotation protocol requires a class that adopts that protocol to implement the
coordinate property. It can also optionally implement
title and subtitle
properties. In that case, that text will be displayed in the annotation callout when the user taps the annotation.
Actually, you already have one class that meets that criteria —
And that’s why, when you create the
Destination class in Chapter 11 (I told you that I would explain this), I have you add the property with the attributes in the way I do. Annotations are required by the protocol to have the properties I have bolded in the following code:
nonatomic, readwrite, copy) NSString *title;
nonatomic, readwrite, copy) NSString *subtitle;
That’s it. You already have the properties in place and initialized (see Chapter 12 if you need to review why that’s the ...