title: Using mapViewDidChangeVisibleRegion with CLGeocoder to return name of the country
body: <p>I just want to return the name of the country where the black circle stops.
  [1]: <a href="https://i.stack.imgur.com/Re5FK.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/Re5FK.jpg</a>
  Example in the picture above</p>
  <p>I know it can be done by <strong>CLGeocoder</strong> and <strong>CLPlacemark</strong> along with <strong>Mapkit</strong>, and I have tried a lot but always got an error and the app would crash.</p>
  <p>my code</p>
  <pre><code>import MapKit
  import SwiftUI
  
  struct MapView: UIViewRepresentable {
      
      @Binding var centralCoordinate: CLLocationCoordinate2D
      var anotations: [MKPointAnnotation]
      
      func makeUIView(context: Context) -&gt; MKMapView{
          let mapview = MKMapView()
          mapview.delegate = context.coordinator
          return mapview
      }
      
      func updateUIView(_ view: MKMapView, context: Context) {
          
          if anotations.count != view.annotations.count {
              view.removeAnnotations(view.annotations)
              view.addAnnotations(anotations)
          }
      }
      
      func makeCoordinator() -&gt; Coordinator {
          Coordinator(self)
      }
      
      class Coordinator: NSObject, MKMapViewDelegate {
          var parent: MapView
          
          init(_ parent: MapView) {
              self.parent = parent
          }
          
          func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
  
              parent.centralCoordinate = mapView.centerCoordinate
  
              let geoCoder = CLGeocoder()
              let location = CLLocation(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude)
              geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -&gt; Void in
                  
                  // Place details
                  var placeMark: CLPlacemark!
                  placeMark = placemarks?[1]
                  // Country
                  if let country = placeMark.country {
                      print(country)
                  }
              })
          }
      }
  }
  
  extension MKPointAnnotation{
      static var eample: MKPointAnnotation {
          let annotaton = MKPointAnnotation()
          annotaton.title = &quot;London&quot;
          annotaton.subtitle = &quot;Home TO 2012 Summer Olampics&quot;
          annotaton.coordinate = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.13)
          return annotaton
      }
  }
  
  struct MapView_Previews: PreviewProvider {
      static var previews: some View {
          MapView(centralCoordinate: .constant(MKPointAnnotation.eample.coordinate), anotations: [MKPointAnnotation.eample])
      }
  }
  </code></pre>
  <p>my view code</p>
  <pre><code>import  MapKit
  import SwiftUI
  
  struct MapViewIntegration: View {
      
      @State private var centercoordinate = CLLocationCoordinate2D()
      @State private var locations = [MKPointAnnotation]()
      
      var body: some View {
          ZStack {
              MapView(centralCoordinate: $centercoordinate,anotations: locations)
          .edgesIgnoringSafeArea(.all)
          Circle()
          .opacity(0.3)
          .frame(width: 32, height: 32)
              VStack{
                  Spacer()
                  HStack{
                      Spacer()
                      Button(action: {
                          let newLocations = MKPointAnnotation()
                             newLocations.coordinate = self.centercoordinate
                             self.locations.append(newLocations)
                      }) {
                          Image(systemName: &quot;plus&quot;)
                      }.padding()
                      .background(Color.white)
                      .font(.title)
                      .clipShape(Circle())
                      .padding(.trailing)
                  }
              }
          }
      }
  }
  
  struct MapViewIntegration_Previews: PreviewProvider {
      static var previews: some View {
          MapViewIntegration()
      }
  }
  </code></pre>
  <p>please help,
  thanks in advance</p>