Skip to content

Instantly share code, notes, and snippets.

@NxSoftware
Created February 4, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NxSoftware/b35833f73aaef9b24e50e2087a4638d9 to your computer and use it in GitHub Desktop.
Save NxSoftware/b35833f73aaef9b24e50e2087a4638d9 to your computer and use it in GitHub Desktop.
Swift Geocoder
let geocoder = CLGeocoder()
let location = CLLocation(latitude: 47.640320, longitude: -122.134400)
geocoder.reverseGeocodeLocation(location) { (addressList, error) in
if let error = error {
print("Unable to Reverse Geocode Location (\(error))")
} else {
print(addressList?.first?.compactAddress ?? "No Matching Addresses Found")
}
}
extension CLPlacemark {
var compactAddress: String {
return "\(thoroughfare ?? ""), \(locality ?? ""), \(country ?? "")"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment