Reputation: 253
Is it possible to get the name of the city and put that one into an array of strings from the user location, using Mapkit? I already know how to get the user location so you dont have to go into that.
Upvotes: 1
Views: 399
Reputation: 831
Yes you can with using CLGeocoder class try to use this code
CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: newCoordinates.latitude, longitude: newCoordinates.longitude),
completionHandler: {(placemarks, error) -> Void in
if error != nil {
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}
if placemarks!.count > 0 {
let pm = placemarks![0]
let c = pm.locality // city of place mark
}
else {
annotation.title = "Unknown Place"
self.outletOfMapView.addAnnotation(annotation)
print("Problem with the data received from geocoder")
}
})
Upvotes: 1