I saw few questions on SO but all of them are old in Swift 2. I got this function from Apple website to convert a city name to latitude and longitude but I am not sure what the function will return (since there is nothing after return statement) and what should I pass. Would someone explain it a lil or show me how to use it please.
func getCoordinate( addressString : String,
completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void ) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(addressString) { (placemarks, error) in
if error == nil {
if let placemark = placemarks?[0] {
let location = placemark.location!
completionHandler(location.coordinate, nil)
return
}
}
completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
}
}