From 7102104730606024e5a05d5eca5b5df7b79dc696 Mon Sep 17 00:00:00 2001 From: Jungpyo Hong <54448459+jphong1111@users.noreply.github.com> Date: Mon, 3 May 2021 10:13:33 -0500 Subject: [PATCH] Update LocationManager.swift --- Helper/LocationManager.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Helper/LocationManager.swift b/Helper/LocationManager.swift index a9af641..26f49db 100644 --- a/Helper/LocationManager.swift +++ b/Helper/LocationManager.swift @@ -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) + } + } +} +