Update LocationManager.swift

This commit is contained in:
Jungpyo Hong 2021-05-03 10:13:33 -05:00 committed by GitHub
parent aaaa1b83a9
commit 7102104730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,3 +61,18 @@ extension LocationManager: CLLocationManagerDelegate {
}
}
extension LocationManager: MKLocalSearchCompleterDelegate {
func getPlaceLocation(with location: CLLocation, completion: @escaping ((String?) -> Void)) {
let geoCoder = CLGeocoder()
geoCoder.reverseGeocodeLocation(location, preferredLocale: .current) { place, error in
guard let place = place?.last, error == nil else {
completion("")
return
}
let joinedAddressArray = [place.thoroughfare, place.locality, place.administrativeArea, place.country, place.postalCode].compactMap { $0 }.joined(separator: " ")
completion(joinedAddressArray)
}
}
}