How to get an address from coordinates using MapKit?
I have this code when long press on the map it gets the coordinates:
func didLongPressMap(sender
Thanks to @Kampi for this. This is an updated Swift 2.0 (Xcode 7) Version:
func setUsersClosestCity()
{
let geoCoder = CLGeocoder()
let location = CLLocation(latitude: _point1.coordinate.latitude, longitude: _point1.coordinate.longitude)
geoCoder.reverseGeocodeLocation(location)
{
(placemarks, error) -> Void in
let placeArray = placemarks as [CLPlacemark]!
// Place details
var placeMark: CLPlacemark!
placeMark = placeArray?[0]
// Address dictionary
print(placeMark.addressDictionary)
// Location name
if let locationName = placeMark.addressDictionary?["Name"] as? NSString
{
print(locationName)
}
// Street address
if let street = placeMark.addressDictionary?["Thoroughfare"] as? NSString
{
print(street)
}
// City
if let city = placeMark.addressDictionary?["City"] as? NSString
{
print(city)
}
// Zip code
if let zip = placeMark.addressDictionary?["ZIP"] as? NSString
{
print(zip)
}
// Country
if let country = placeMark.addressDictionary?["Country"] as? NSString
{
print(country)
}
}
}