Skip to content

Instantly share code, notes, and snippets.

@davidseek
Created September 5, 2018 18:16
Show Gist options
  • Select an option

  • Save davidseek/0bd22ff6134fa5f920e875703f2279d2 to your computer and use it in GitHub Desktop.

Select an option

Save davidseek/0bd22ff6134fa5f920e875703f2279d2 to your computer and use it in GitHub Desktop.
// MARK: - Get Location
extension LocationManager {
func getLocation(forPlaceCalled name: String,
completion: @escaping(CLLocation?) -> Void) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(name) { placemarks, error in
guard error == nil else {
print("*** Error in \(#function): \(error!.localizedDescription)")
completion(nil)
return
}
guard let placemark = placemarks?[0] else {
print("*** Error in \(#function): placemark is nil")
completion(nil)
return
}
guard let location = placemark.location else {
print("*** Error in \(#function): placemark is nil")
completion(nil)
return
}
completion(location)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment