Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a view conform to MapAnnotationProtocol

I have a tappable MapAnnotation and whenever I try to customize the "look" of the annotation pin, I get the following error:

Initializer ‘init(coordinateRegion:interactionModes:showsUserLocation:userTrackingMode:annotationItems:annotationContent:)’ requires that ‘NavigationLink<PlaceAnnotationView, LocationDetailsView>’ conform to ‘MapAnnotationProtocol’

Annotation is defined by this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

struct Annotation: Codable, Identifiable, Hashable {
    @DocumentID var id: String?
    let lat: String?
    let lng: String?
    var name: String
}

And the Map is defined by this:

Map(coordinateRegion: $region, annotationItems: annotations) { place in
    NavigationLink {
        LocationDetailsView(place: place.name)
    } label: {
        PlaceAnnotationView(title: place.name)
    }
}

Have I forgotten to define something? Please let me know. Thanks.

>Solution :

https://developer.apple.com/documentation/mapkit/mapannotationprotocol

Don’t create types conforming to MapAnnotationProtocol protocol. Instead, use one of the framework-provided types MapAnnotation, MapMarker, and MapPin.

https://developer.apple.com/documentation/mapkit/mapannotation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading