Hi so my function getLatFromAddress() is asynchronous and i need it run normally.
func getLatFromAddress(withAddress address: String, completionHandler: @escaping (Double) -> Void) {
let geocoder = CLGeocoder()
// Use CLGeocoder to convert the address into coordinates
geocoder.geocodeAddressString(address) { (placemarks, error) in
// Return early if there was an error
guard error == nil else {
return
}
// Return early if no placemarks were found
guard let placemarks = placemarks, !placemarks.isEmpty else {
return
}
// Use the first placemark to obtain the coordinates
let location = placemarks.first!.location
print("lat : ",location!.coordinate.latitude)
completionHandler(location!.coordinate.latitude)
}
}
how i use it :
lat1 = 0.00
getLat(withAddress: address1) { (result) in
lat1 = result
}
print("lat outFunc = ",lat1)
log :
lat outFunc = 0.00
lat : 43.6044242