title: How do you let a user add a pin to a map and get the coordinates in SwiftUI?
body: <p>I have a map in a view that is centered on Chicago. I want the user to be able to place a pin/annotation on the map and then retrieve those coordinates. The map loads Chicago fine but I can't get the annotation code to work.</p>
  
  <p>I can't seem to find an answer for SwiftUI, specifically. Only Swift and Storyboards. I feel like I have 99% of the code but the pieces aren't in the right spots. I included a screen shot of where the errors are. Thanks for your help.</p>
  
  <pre><code>import SwiftUI
  import MapKit
  
  struct EntireMapView: UIViewRepresentable {
  
      func updateUIView(_ mapView: MKMapView, context: Context) {
  
          mapView.delegate = context.coordinator
  
          let longPressGesture = UILongPressGestureRecognizer(target: mapView, action: #selector(EntireMapViewCoordinator.addAnnotation(gesture:)))
          mapView.addGestureRecognizer(longPressGesture)
  
          let span = MKCoordinateSpan(latitudeDelta: 0.3, longitudeDelta: 0.3)
  
          var chicagoCoordinate = CLLocationCoordinate2D()
          chicagoCoordinate.latitude = 41.878113
          chicagoCoordinate.longitude = -87.629799
  
          let region = MKCoordinateRegion(center: chicagoCoordinate, span: span)
  
          mapView.setRegion(region, animated: true)
  
      }
  
      func makeUIView(context: Context) -&gt; MKMapView {
  
          let mapView = MKMapView(frame: .zero)
          mapView.delegate = context.coordinator
          return mapView
  
      }
  
      func makeCoordinator() -&gt; EntireMapViewCoordinator {
          return EntireMapViewCoordinator(self)
      }
  
      class EntireMapViewCoordinator: NSObject, MKMapViewDelegate {
  
          var entireMapViewController: EntireMapView
  
          init(_ control: EntireMapView) {
            self.entireMapViewController = control
          }
  
          func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -&gt; MKAnnotationView? {
              return (annotation as? MKAnnotationView)!
          }
  
          @objc func addAnnotation(gesture: UILongPressGestureRecognizer) {
  
              if gesture.state == .ended {
  
                  let point = gesture.location(in: self.mapView) **&lt;--- ERROR HERE**
                  let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
  
                  var annotation = MKPointAnnotation()
                  annotation.coordinate = coordinate
  
                  self.mapView.addAnnotation(annotation) **&lt;--- ERROR HERE**
              }
          }
      }
  }
  
  struct EntireMapView_Previews: PreviewProvider {
      static var previews: some View {
          EntireMapView()
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ALvYb.png" rel="noreferrer">Here's a screen shot of the errors</a></p>