0

Hi I am making swiftui app using mapkit. I wanted to convert coordinate of element into address as a string, but CLGeocoder().reverseGeocodeLocation returns empty string. Here is my test code.

import SwiftUI
import MapKit

struct TestView: View {
    
    var address: String {
        var street = ""
        CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: 53.958332, longitude: -1.080278), preferredLocale: nil) { placemarks, error in
            if let error = error {
                print(error)
            }else{
                guard let placeMark = placemarks?.first else {
                    print("No placemark from Apple: \(String(describing: error))")
                    return
                }
                    
                street = placeMark.thoroughfare ?? "error"
            }
        }
        return street
    }
    
    var body: some View {
        Text(address)
    }
}

Please help.

green8
  • 376
  • 2
  • 14

0 Answers0