You can use CLGeocoder geocodeAddressString method. It will return an array of CLPlacemark objects that contain gps coords and city, location info.
let address = "Burlington, Vermont"
CLGeocoder().geocodeAddressString(address, completionHandler: { placemarks, error in
if (error != nil) {
return
}
if let placemark = placemarks?[0] {
let lat = String(format: "%.04f", (placemark.location?.coordinate.longitude ?? 0.0)!)
let lon = String(format: "%.04f", (placemark.location?.coordinate.latitude ?? 0.0)!)
let name = placemark.name!
let country = placemark.country!
let region = placemark.administrativeArea!
print("\(lat),\(lon)\n\(name),\(region) \(country)")
}
})
}
To go the other way, from GPS coords use reverGeocodeLocation method
let lat = 12.000
let lon = 34.000
if let loc = CLLocation(latitude: lat, longitude: lon) as? CLLocation {
CLGeocoder().reverseGeocodeLocation(loc, completionHandler: { (placemarks, error) in
if let placemark = placemarks?[0] {
let lat = String(format: "%.04f", (placemark.location?.coordinate.longitude ?? 0.0)!)
let lon = String(format: "%.04f", (placemark.location?.coordinate.latitude ?? 0.0)!)
let name = placemark.name!
let country = placemark.country!
let region = placemark.administrativeArea!
print("\(lat),\(lon)\n\(name),\(region) \(country)")
}
})
Just finishing up brewing up some fresh ground comments...