From e8a7c9c83e93e2b14e4c0a492090302dbdcd5781 Mon Sep 17 00:00:00 2001 From: Dmitry Klimkin Date: Wed, 17 Jan 2018 09:03:38 +1100 Subject: [PATCH 1/2] Fixed location from address geocoding --- Sources/GeocoderRequest.swift | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Sources/GeocoderRequest.swift b/Sources/GeocoderRequest.swift index 620f170d..249aa2d8 100644 --- a/Sources/GeocoderRequest.swift +++ b/Sources/GeocoderRequest.swift @@ -209,32 +209,31 @@ public final class Geocoder_Apple: GeocoderRequest { let geocoder = CLGeocoder() self.task = geocoder + + let feocodeCompletionHandler: CoreLocation.CLGeocodeCompletionHandler = { [weak self] (placemarks, error) in + guard let this = self else { return } + + this.isFinished = true + + if let err = error { + this.failure?(LocationError.other(err.localizedDescription)) + return + } + + this.success?(Place.load(placemarks: placemarks ?? [])) + } + switch self.operation { case .getLocation(let address, let region): - geocoder.geocodeAddressString(address, in: region, completionHandler: { (placemarks, error) in - self.isFinished = true - }) + geocoder.geocodeAddressString(address, in: region, completionHandler: feocodeCompletionHandler) case .getPlace(let coordinates, let locale): let loc = CLLocation(latitude: coordinates.latitude, longitude: coordinates.longitude) + if #available(iOS 11, *) { - geocoder.reverseGeocodeLocation(loc, preferredLocale: locale, completionHandler: { (placemarks, error) in - self.isFinished = true - if let err = error { - self.failure?(LocationError.other(err.localizedDescription)) - return - } - self.success?(Place.load(placemarks: placemarks ?? [])) - }) + geocoder.reverseGeocodeLocation(loc, preferredLocale: locale, completionHandler: feocodeCompletionHandler) } else { // Fallback on earlier versions - geocoder.reverseGeocodeLocation(loc, completionHandler: { (placemarks, error) in - self.isFinished = true - if let err = error { - self.failure?(LocationError.other(err.localizedDescription)) - return - } - self.success?(Place.load(placemarks: placemarks ?? [])) - }) + geocoder.reverseGeocodeLocation(loc, completionHandler: feocodeCompletionHandler) } } } From a82fc1a1a30ba9a09a4976afad8b6dadfc2ddf1d Mon Sep 17 00:00:00 2001 From: Dev4Jam Date: Wed, 17 Jan 2018 09:19:21 +1100 Subject: [PATCH 2/2] Fixed variable typo --- Sources/GeocoderRequest.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/GeocoderRequest.swift b/Sources/GeocoderRequest.swift index 249aa2d8..28193416 100644 --- a/Sources/GeocoderRequest.swift +++ b/Sources/GeocoderRequest.swift @@ -210,7 +210,7 @@ public final class Geocoder_Apple: GeocoderRequest { let geocoder = CLGeocoder() self.task = geocoder - let feocodeCompletionHandler: CoreLocation.CLGeocodeCompletionHandler = { [weak self] (placemarks, error) in + let geocodeCompletionHandler: CoreLocation.CLGeocodeCompletionHandler = { [weak self] (placemarks, error) in guard let this = self else { return } this.isFinished = true @@ -225,15 +225,15 @@ public final class Geocoder_Apple: GeocoderRequest { switch self.operation { case .getLocation(let address, let region): - geocoder.geocodeAddressString(address, in: region, completionHandler: feocodeCompletionHandler) + geocoder.geocodeAddressString(address, in: region, completionHandler: geocodeCompletionHandler) case .getPlace(let coordinates, let locale): let loc = CLLocation(latitude: coordinates.latitude, longitude: coordinates.longitude) if #available(iOS 11, *) { - geocoder.reverseGeocodeLocation(loc, preferredLocale: locale, completionHandler: feocodeCompletionHandler) + geocoder.reverseGeocodeLocation(loc, preferredLocale: locale, completionHandler: geocodeCompletionHandler) } else { // Fallback on earlier versions - geocoder.reverseGeocodeLocation(loc, completionHandler: feocodeCompletionHandler) + geocoder.reverseGeocodeLocation(loc, completionHandler: geocodeCompletionHandler) } } }