From f3edaa13b88d17e70baf091b0fd71bcf5137311b Mon Sep 17 00:00:00 2001 From: Julien Zarka Date: Tue, 24 Mar 2020 17:40:57 +0100 Subject: [PATCH 1/6] Add support for not consistent fields (street, town). --- example/dump.dart | 2 ++ lib/src/model.dart | 4 ++++ lib/src/model.g.dart | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/example/dump.dart b/example/dump.dart index 9010153..ce6013c 100644 --- a/example/dump.dart +++ b/example/dump.dart @@ -33,11 +33,13 @@ class Dumper { print(' stateDistrict: ${r.components?.stateDistrict}'); print(' suburb: ${r.components?.suburb}'); print(' city: ${r.components?.city}'); + print(' town: ${r.components?.town}'); print(' cityDistrict: ${r.components?.cityDistrict}'); print(' politicalUnion: ${r.components?.politicalUnion}'); print(' county: ${r.components?.county}'); print(' houseNumber: ${r.components?.houseNumber}'); print(' road: ${r.components?.road}'); + print(' street: ${r.components?.street}'); print(' annotations:'); print(' callingCode: ${r.annotations?.callingCode}'); print(' dms: ${r.annotations?.dms}'); diff --git a/lib/src/model.dart b/lib/src/model.dart index f394bec..342e416 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -318,11 +318,13 @@ class Currency { @JsonSerializable() class Components { + final String town; final String city; final String state; final String country; final String county; final String road; + final String street; final String suburb; @JsonKey(name: 'house_number') final String houseNumber; @@ -345,9 +347,11 @@ class Components { this.stateDistrict, this.county, this.city, + this.town, this.cityDistrict, this.suburb, this.road, + this.street, this.houseNumber, this.politicalUnion, ); diff --git a/lib/src/model.g.dart b/lib/src/model.g.dart index 4c0c6f3..d80ab5e 100644 --- a/lib/src/model.g.dart +++ b/lib/src/model.g.dart @@ -282,10 +282,12 @@ Components _$ComponentsFromJson(Map json) { json['state'] as String, json['state_district'] as String, json['county'] as String, + json['town'] as String, json['city'] as String, json['city_district'] as String, json['suburb'] as String, json['road'] as String, + json['street'] as String, json['house_number'] as String, json['political_union'] as String, ); @@ -293,11 +295,13 @@ Components _$ComponentsFromJson(Map json) { Map _$ComponentsToJson(Components instance) => { + 'town': instance.town, 'city': instance.city, 'state': instance.state, 'country': instance.country, 'county': instance.county, 'road': instance.road, + 'street': instance.street, 'suburb': instance.suburb, 'house_number': instance.houseNumber, 'country_code': instance.countryCode, From 8a0c386fa8b7fc9c4da84722e692ee2560ca71ed Mon Sep 17 00:00:00 2001 From: Julien Zarka Date: Tue, 24 Mar 2020 17:41:10 +0100 Subject: [PATCH 2/6] Add support for field postcode. --- lib/src/model.dart | 3 +++ lib/src/model.g.dart | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/src/model.dart b/lib/src/model.dart index 342e416..8e7a048 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -325,6 +325,8 @@ class Components { final String county; final String road; final String street; + @JsonKey(name: 'postcode') + final String postCode; final String suburb; @JsonKey(name: 'house_number') final String houseNumber; @@ -352,6 +354,7 @@ class Components { this.suburb, this.road, this.street, + this.postCode, this.houseNumber, this.politicalUnion, ); diff --git a/lib/src/model.g.dart b/lib/src/model.g.dart index d80ab5e..9c8819f 100644 --- a/lib/src/model.g.dart +++ b/lib/src/model.g.dart @@ -288,6 +288,7 @@ Components _$ComponentsFromJson(Map json) { json['suburb'] as String, json['road'] as String, json['street'] as String, + json['postcode'] as String, json['house_number'] as String, json['political_union'] as String, ); @@ -302,6 +303,7 @@ Map _$ComponentsToJson(Components instance) => 'county': instance.county, 'road': instance.road, 'street': instance.street, + 'postcode': instance.postCode, 'suburb': instance.suburb, 'house_number': instance.houseNumber, 'country_code': instance.countryCode, From d606de144ccdea1e76c0f91a977967850da3c29d Mon Sep 17 00:00:00 2001 From: Julien Zarka Date: Tue, 24 Mar 2020 17:42:20 +0100 Subject: [PATCH 3/6] Fix reverse geocode encoding due to unsupported %2B --- lib/src/geocoder.dart | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/src/geocoder.dart b/lib/src/geocoder.dart index 12e7db0..d46c9fe 100644 --- a/lib/src/geocoder.dart +++ b/lib/src/geocoder.dart @@ -61,19 +61,19 @@ class Geocoder { bool noRecord = false, bool addRequest = false, }) { - return geocode( - "${latitude}+${longitude}", - language: language, - countryCode: countryCode, - bounds: bounds, - abbrv: abbrv, - limit: limit, - minConfidence: minConfidence, - noAnnotations: noAnnotations, - noDedupe: noDedupe, - noRecord: noRecord, - addRequest: addRequest, - ); + return _send({ + 'q': {'latitude': latitude, 'longitude': longitude}, + 'language': language, + 'countryCode': countryCode, + 'bounds': bounds, + 'limit': limit, + 'no_annotations': noAnnotations, + 'min_confidence': minConfidence, + 'add_request': addRequest, + 'no_dedupe': noDedupe, + 'no_record': noRecord, + 'abbrv': abbrv, + }); } Future _send(Map args) async { @@ -101,6 +101,9 @@ class Geocoder { if (value is bool) { return value ? "1" : "0"; } + if (value is Map) { + return '${value['latitude']}+${value['longitude']}'; + } if (value is Bounds) { return "${value.northeast.longitude}%2C${value.northeast.latitude}%2C${value.southwest.longitude}%2C${value.southwest.latitude}"; } From ef0bd4d38d2acd326d10d94c93b406b38017a711 Mon Sep 17 00:00:00 2001 From: Julien Zarka Date: Tue, 24 Mar 2020 17:43:16 +0100 Subject: [PATCH 4/6] Cosmetics: move away from double quote. --- lib/src/geocoder.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/geocoder.dart b/lib/src/geocoder.dart index d46c9fe..6c9b663 100644 --- a/lib/src/geocoder.dart +++ b/lib/src/geocoder.dart @@ -8,18 +8,18 @@ import 'model.dart'; /// /// More details here : https://opencagedata.com/. class Geocoder { - static const String host = "https://api.opencagedata.com/geocode/v1/json"; + static const String host = 'https://api.opencagedata.com/geocode/v1/json'; final String _baseUrl; /// Create an OpenCage geocoder for the given [apiKey]. - const Geocoder(String apiKey) : this._baseUrl = "${host}?key=${apiKey}"; + const Geocoder(String apiKey) : this._baseUrl = '${host}?key=${apiKey}'; /// Get coordinates and data from a search [query]. /// /// All optional parameters are described here : https://opencagedata.com/api#request. Future geocode(String query, - {String language = "en", + {String language = 'en', String countryCode = null, Bounds bounds = null, bool abbrv = false, @@ -40,7 +40,7 @@ class Geocoder { 'add_request': addRequest, 'no_dedupe': noDedupe, 'no_record': noRecord, - 'abbrv': abbrv + 'abbrv': abbrv, }); } @@ -50,7 +50,7 @@ class Geocoder { Future reverseGeocode( double latitude, double longitude, { - String language = "en", + String language = 'en', String countryCode = null, Bounds bounds = null, bool abbrv = false, @@ -91,7 +91,7 @@ class Geocoder { queryArgs.forEach((key, value) { if (value != null && value != false) { var formattedValue = _formatQueryArgValue(value); - result.write("&${key}=${formattedValue}"); + result.write('&${key}=${formattedValue}'); } }); return Uri.parse(result.toString()); @@ -99,13 +99,13 @@ class Geocoder { String _formatQueryArgValue(Object value) { if (value is bool) { - return value ? "1" : "0"; + return value ? '1' : '0'; } if (value is Map) { return '${value['latitude']}+${value['longitude']}'; } if (value is Bounds) { - return "${value.northeast.longitude}%2C${value.northeast.latitude}%2C${value.southwest.longitude}%2C${value.southwest.latitude}"; + return '${value.northeast.longitude}%2C${value.northeast.latitude}%2C${value.southwest.longitude}%2C${value.southwest.latitude}'; } if (value is int || value is double) { return value.toString(); From e689743320bb7173b75c08c3dcadac76db442239 Mon Sep 17 00:00:00 2001 From: Julien Zarka Date: Tue, 24 Mar 2020 17:44:38 +0100 Subject: [PATCH 5/6] Add new parameter support roadinfo for closest road mapmatch. --- lib/src/geocoder.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/geocoder.dart b/lib/src/geocoder.dart index 6c9b663..f8837c0 100644 --- a/lib/src/geocoder.dart +++ b/lib/src/geocoder.dart @@ -28,6 +28,7 @@ class Geocoder { bool noAnnotations = false, bool noDedupe = false, bool noRecord = false, + bool roadInfo = false, bool addRequest = false}) { return _send({ 'q': query, @@ -40,6 +41,7 @@ class Geocoder { 'add_request': addRequest, 'no_dedupe': noDedupe, 'no_record': noRecord, + 'roadinfo': roadInfo, 'abbrv': abbrv, }); } @@ -59,6 +61,7 @@ class Geocoder { bool noAnnotations = false, bool noDedupe = false, bool noRecord = false, + bool roadInfo = false, bool addRequest = false, }) { return _send({ @@ -72,6 +75,7 @@ class Geocoder { 'add_request': addRequest, 'no_dedupe': noDedupe, 'no_record': noRecord, + 'roadinfo': roadInfo, 'abbrv': abbrv, }); } From 60a0cb9a37f0f0bf98c62decd59a976ba6067843 Mon Sep 17 00:00:00 2001 From: Julien Zarka Date: Tue, 24 Mar 2020 17:44:52 +0100 Subject: [PATCH 6/6] Dump postcode. --- example/dump.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/dump.dart b/example/dump.dart index ce6013c..c31bc0b 100644 --- a/example/dump.dart +++ b/example/dump.dart @@ -40,6 +40,7 @@ class Dumper { print(' houseNumber: ${r.components?.houseNumber}'); print(' road: ${r.components?.road}'); print(' street: ${r.components?.street}'); + print(' postCode: ${r.components?.postCode}'); print(' annotations:'); print(' callingCode: ${r.annotations?.callingCode}'); print(' dms: ${r.annotations?.dms}'); @@ -71,4 +72,4 @@ class Dumper { print(' thousandsSeparator: ${r.annotations?.currency?.thousandsSeparator}'); }); } -} \ No newline at end of file +}