MGLAnnotation

@protocol MGLAnnotation <NSObject>

The MGLAnnotation protocol is used to provide annotation-related information to a map view. To use this protocol, you adopt it in any custom objects that store or represent annotation data. Each object then serves as the source of information about a single map annotation and provides critical information, such as the annotation’s location on the map. Annotation objects do not provide the visual representation of the annotation but typically coordinate (in conjunction with the map view’s delegate) the creation of an appropriate objects to handle the display.

An object that adopts this protocol must implement the coordinate property. The other methods of this protocol are optional.

See the Annotation models and Annotation views examples to learn how to add objects that follow the MGLAnnotation protocol.

  • The center point (specified as a map coordinate) of the annotation. (required) (read-only)

    Declaration

    Objective-C

    @property (readonly, nonatomic) CLLocationCoordinate2D coordinate;

    Swift

    var coordinate: CLLocationCoordinate2D { get }
  • The string containing the annotation’s title.

    Although this property is optional, if you support the selection of annotations in your map view, you are expected to provide this property. This string is displayed in the callout for the associated annotation.

    Declaration

    Objective-C

    @optional
    @property (readonly, copy, nonatomic, nullable) NSString *title;

    Swift

    optional var title: String? { get }
  • The string containing the annotation’s subtitle.

    This string is displayed in the callout for the associated annotation.

    Declaration

    Objective-C

    @optional
    @property (readonly, copy, nonatomic, nullable) NSString *subtitle;

    Swift

    optional var subtitle: String? { get }