I want to find current location name from latitude and longitude,
Here is my code snippet I tried but my log shows null value in all the places except in place
Here's how to get the address from Location Coordinate (lat,long).
You can get the address info such like city, country, postcode etc. from LocationCoordinates with this code
func getReverSerGeoLocation(location : CLLocation) {
print("getting Address from Location cordinate")
CLGeocoder().reverseGeocodeLocation(location) {
placemarks , error in
if error == nil && placemarks!.count > 0 {
guard let placemark = placemarks?.last else {
return
}
print(placemark.thoroughfare)
print(placemark.subThoroughfare)
print("postalCode :-",placemark.postalCode)
print("City :-",placemark.locality)
print("subLocality :-",placemark.subLocality)
print("subAdministrativeArea :-",placemark.subAdministrativeArea)
print("Country :-",placemark.country)
}
}
}
Just call above method by passing latitude longitude as argument such like below
getReverSerGeoLocation(location: CLLocation(latitude: 21.0225, longitude: 72.5714))
Hope this helps!