Annotate markpin on map using mapkit map

Hi I am trying to annotate on map after displaying the map. I am able to take in lat and long from user and convert it to Double. But stuck at the annotate on the map part.

I am able to annotate hard coded values but I do not know how to convert it to annotate using user`s input of lat and long.

I struggling to include the init( ...) part into my identifiable portion. I cant seem to get it right.

I found this link from apple but it doesnt work. https://developer.apple.com/documentation/mapkit/mapmarker#see-also


import MapKit
import SwiftUI

struct IdentifiablePlace: Identifiable {
    let id: UUID
    let location: CLLocationCoordinate2D
    init(id: UUID = UUID(), lat: Double, long: Double) {
        self.id = id
        self.location = CLLocationCoordinate2D(
            latitude: lat,
            longitude: long)
    }
}

struct PinAnnotationMapView: View {
    let place: IdentifiablePlace
    @State var region: MKCoordinateRegion

    var body: some View {
        Map(coordinateRegion: $region,
            annotationItems: [place])
        { place in
            MapMarker(coordinate: place.location,
                   tint: Color.purple)
        }
    }
}

Thanks

What I am trying to achieve is when user key in lat and long values and pressed the button, it will annotate on the map.

Annotate markpin on map using mapkit map
 
 
Q