From 56b45540350cff2ded24606b5104f5379f45ab3b Mon Sep 17 00:00:00 2001 From: Sebastian Baar Date: Sun, 10 Mar 2019 13:31:43 +0100 Subject: [PATCH] update plugin to v3.2.0 - result array returns the same information for forward and reverse geocoding (closes #35) - result array return points of interest string array for iOS and Android (closes #38) - results[0].areasOfInterest = ["Brandenburger Tor"] - update dependency 'cordova-plugin-add-swift-support' to 1.7.2 --- CHANGELOG.md | 11 ++++++++ README.md | 23 +++++++++++++---- package.json | 2 +- plugin.xml | 4 +-- src/android/NativeGeocoder.java | 24 ++++++++++++++---- src/ios/NativeGeocoder.swift | 45 +++++++++++++++++++++++---------- www/NativeGeocoder.js | 13 +++++----- 7 files changed, 88 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9afdf78..f716e58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# 3.2.0 (2019-03-10) + +- result array returns the same information for forward and reverse geocoding (closes #35) +- result array return points of interest string array for iOS and Android (closes #38) + - results[0].areasOfInterest = ["Brandenburger Tor"] +- update dependency 'cordova-plugin-add-swift-support' to 1.7.2 + +## ** BREAKING CHANGES ** +- replace __NativeGeocoderForwardResult__ with __NativeGeocoderResult__ +- replace __NativeGeocoderReverseResult__ with __NativeGeocoderResult__ + # 3.1.3 (2018-11-12) Android: return empty String if Address property is null (closes #34) diff --git a/README.md b/README.md index 21a1b77..8aa61fe 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,12 @@ All available `options` attributes: | `maxResults` | `Number` | 1 | Optional. Min value: 1, max value: 5. | ### Array -Conforms to [Apple's](https://developer.apple.com/documentation/corelocation/clplacemark) and [Android's](https://developer.android.com/reference/android/location/Address.html) reverse geocoder's result arrays. +Conforms to [Apple's](https://developer.apple.com/documentation/corelocation/clplacemark) and [Android's](https://developer.android.com/reference/android/location/Address.html) geocoder's result arrays. | Value | Type | |-------------|----------- +| `latitude` | `String` | +| `longitude` | `String` | | `countryCode` | `String` | | `postalCode` | `String` | | `administrativeArea` | `String` | @@ -61,7 +63,8 @@ Conforms to [Apple's](https://developer.apple.com/documentation/corelocation/clp | `locality` | `String` | | `subLocality` | `String` | | `thoroughfare` | `String` | -| `subThoroughfare` | `String` | +| `subThoroughfare` | `String` | +| `areasOfInterest` | `Array` | ### Example ```js @@ -98,11 +101,21 @@ All available `options` attributes: | `maxResults` | `Number` | 1 | Optional. Min value: 1, max value: 5. | ### Array +Conforms to [Apple's](https://developer.apple.com/documentation/corelocation/clplacemark) and [Android's](https://developer.android.com/reference/android/location/Address.html) geocoder's result arrays. + | Value | Type | |-------------|----------- -| `latitude` | `String` | -| `longitude` | `String` | - +| `latitude` | `String` | +| `longitude` | `String` | +| `countryCode` | `String` | +| `postalCode` | `String` | +| `administrativeArea` | `String` | +| `subAdministrativeArea` | `String` | +| `locality` | `String` | +| `subLocality` | `String` | +| `thoroughfare` | `String` | +| `subThoroughfare` | `String` | +| `areasOfInterest` | `Array` | ### Example ```js diff --git a/package.json b/package.json index bc4b79b..73f212b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-nativegeocoder", - "version": "3.1.3", + "version": "3.2.0", "description": "Cordova plugin for native forward and reverse geocoding", "cordova": { "id": "cordova-plugin-nativegeocoder", diff --git a/plugin.xml b/plugin.xml index 026d3e5..fae98d2 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + NativeGeocoder Cordova plugin for native forward and reverse geocoding MIT @@ -43,7 +43,7 @@ $LOCATION_WHEN_IN_USE_DESCRIPTION - + \ No newline at end of file diff --git a/src/android/NativeGeocoder.java b/src/android/NativeGeocoder.java index 4ba59b4..5bb8c53 100644 --- a/src/android/NativeGeocoder.java +++ b/src/android/NativeGeocoder.java @@ -99,6 +99,8 @@ private void reverseGeocode(double latitude, double longitude, JSONObject option // https://developer.android.com/reference/android/location/Address.html JSONObject placemark = new JSONObject(); + placemark.put("latitude", !String.valueOf(address.getLatitude()).isEmpty() ? address.getLatitude() : ""); + placemark.put("longitude", !String.valueOf(address.getLongitude()).isEmpty() ? address.getLongitude() : ""); placemark.put("countryCode", address.getCountryCode() != null ? address.getCountryCode() : ""); placemark.put("countryName", address.getCountryName() != null ? address.getCountryName() : ""); placemark.put("postalCode", address.getPostalCode() != null ? address.getPostalCode() : ""); @@ -108,6 +110,7 @@ private void reverseGeocode(double latitude, double longitude, JSONObject option placemark.put("subLocality", address.getSubLocality() != null ? address.getSubLocality() : ""); placemark.put("thoroughfare", address.getThoroughfare() != null ? address.getThoroughfare() : ""); placemark.put("subThoroughfare", address.getSubThoroughfare() != null ? address.getSubThoroughfare() : ""); + placemark.put("areasOfInterest", address.getFeatureName() != null ? new JSONArray(new String[]{ address.getFeatureName()} ) : new JSONArray()); resultObj.put(placemark); } @@ -166,10 +169,22 @@ private void forwardGeocode(String addressString, JSONObject options, CallbackCo String longitude = String.valueOf(address.getLongitude()); if (!latitude.isEmpty() && !longitude.isEmpty()) { - JSONObject coordinates = new JSONObject(); - coordinates.put("latitude", latitude); - coordinates.put("longitude", longitude); - resultObj.put(coordinates); + // https://developer.android.com/reference/android/location/Address.html + JSONObject placemark = new JSONObject(); + placemark.put("latitude", latitude); + placemark.put("longitude", longitude); + placemark.put("countryCode", address.getCountryCode() != null ? address.getCountryCode() : ""); + placemark.put("countryName", address.getCountryName() != null ? address.getCountryName() : ""); + placemark.put("postalCode", address.getPostalCode() != null ? address.getPostalCode() : ""); + placemark.put("administrativeArea", address.getAdminArea() != null ? address.getAdminArea() : ""); + placemark.put("subAdministrativeArea", address.getSubAdminArea() != null ? address.getSubAdminArea() : ""); + placemark.put("locality", address.getLocality() != null ? address.getLocality() : ""); + placemark.put("subLocality", address.getSubLocality() != null ? address.getSubLocality() : ""); + placemark.put("thoroughfare", address.getThoroughfare() != null ? address.getThoroughfare() : ""); + placemark.put("subThoroughfare", address.getSubThoroughfare() != null ? address.getSubThoroughfare() : ""); + placemark.put("areasOfInterest", address.getFeatureName() != null ? new JSONArray(new String[]{ address.getFeatureName() }) : new JSONArray()); + + resultObj.put(placemark); } } catch (RuntimeException e) { @@ -261,7 +276,6 @@ private Geocoder createGeocoderWithOptions(NativeGeocoderOptions geocoderOptions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { locale = Locale.forLanguageTag(geocoderOptions.defaultLocale); } else { - locale = Locale.ENGLISH; String parts[] = geocoderOptions.defaultLocale.split("[-_]", -1); if (parts.length == 1) locale = new Locale(parts[0]); diff --git a/src/ios/NativeGeocoder.swift b/src/ios/NativeGeocoder.swift index baab9e7..15d4386 100644 --- a/src/ios/NativeGeocoder.swift +++ b/src/ios/NativeGeocoder.swift @@ -1,6 +1,8 @@ import CoreLocation -struct NativeGeocoderReverseResult: Encodable { +struct NativeGeocoderResult: Encodable { + var latitude: String? + var longitude: String? var countryCode: String? var countryName: String? var postalCode: String? @@ -10,11 +12,7 @@ struct NativeGeocoderReverseResult: Encodable { var subLocality: String? var thoroughfare: String? var subThoroughfare: String? -} - -struct NativeGeocoderForwardResult: Encodable { - var latitude: String? - var longitude: String? + var areasOfInterest: [String]? } struct NativeGeocoderError { @@ -28,8 +26,8 @@ struct NativeGeocoderOptions: Decodable { } @objc(NativeGeocoder) class NativeGeocoder : CDVPlugin { - typealias ReverseGeocodeCompletionHandler = ([NativeGeocoderReverseResult]?, NativeGeocoderError?) -> Void - typealias ForwardGeocodeCompletionHandler = ([NativeGeocoderForwardResult]?, NativeGeocoderError?) -> Void + typealias ReverseGeocodeCompletionHandler = ([NativeGeocoderResult]?, NativeGeocoderError?) -> Void + typealias ForwardGeocodeCompletionHandler = ([NativeGeocoderResult]?, NativeGeocoderError?) -> Void private static let MAX_RESULTS_COUNT = 5 // MARK: - REVERSE GEOCODE @@ -111,11 +109,15 @@ struct NativeGeocoderOptions: Decodable { if let placemarks = placemarks { let maxResultObjects = placemarks.count >= maxResults ? maxResults : placemarks.count - var resultObj = [NativeGeocoderReverseResult]() + var resultObj = [NativeGeocoderResult]() for i in 0..= maxResults ? maxResults : placemarks.count - var resultObj = [NativeGeocoderForwardResult]() + var resultObj = [NativeGeocoderResult]() for i in 0..