Im trying to obtain the "locality" from Coordinates using CLGeocoder.reverseGeocodeLocation
, but when the execution reach the completionHandler the code inside the bracket is completely skipped to self.currentPlace = (self.place?.locality)! + ", " + (self.place?.thoroughfare)!
freezing the application.
where am I wrong??
func updateLocation() {
let location = CLLocation.init(latitude: currentCoordinates.latitude, longitude: currentCoordinates.longitude)
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in
if (error != nil) {
print("Error")
}else {
let pm = placemarks as [CLPlacemark]!
if pm.count > 0 {
self.place = pm.first
self.stopUpdatingLocation()
}
}
})
self.currentPlace = (self.place?.locality)! + ", " + (self.place?.thoroughfare)!
}