I want to get address using Lat long, But always getting nil. Please help me, How to manage that type of function so that in return will get address. i want to get address while calling, but it give me always nil.
func getAddressFromLatLon(pdblLatitude: String, pdblLongitude: String) -> String {
var addressString : String = ""
var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
let lat: Double = Double("\(pdblLatitude)")!
//21.228124
let lon: Double = Double("\(pdblLongitude)")!
//72.833770
let ceo: CLGeocoder = CLGeocoder()
center.latitude = lat
center.longitude = lon
let loc: CLLocation = CLLocation(latitude:center.latitude, longitude: center.longitude)
ceo.reverseGeocodeLocation(loc, completionHandler:
{(placemarks, error) in
if (error != nil)
{
print("reverse geodcode fail: \(error!.localizedDescription)")
}
let pm = placemarks! as! [CLPlacemark]
if pm.count > 0 {
let pm = placemarks![0]
print("ADDRESS \(pm.country)---\(pm.locality)---\(pm.subLocality)---\(pm.thoroughfare)---\(pm.postalCode)---\(pm.subThoroughfare)")
if pm.subLocality != nil {
addressString = addressString + pm.subLocality! + ", "
}
if pm.thoroughfare != nil {
addressString = addressString + pm.thoroughfare! + ", "
}
if pm.locality != nil {
addressString = addressString + pm.locality! + ", "
}
if pm.country != nil {
addressString = addressString + pm.country! + ", "
}
if pm.postalCode != nil {
addressString = addressString + pm.postalCode! + " "
}
}
})
return addressString
}