From 30e8521aaa4479be4c8daa4d7d1f976fe2bc7f8f Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Thu, 11 Mar 2021 10:27:41 +0900 Subject: [PATCH] fixed geocoding params --- lib/model/source/location.dart | 6 +++--- lib/services/geocoding_service.dart | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/model/source/location.dart b/lib/model/source/location.dart index 5a57d24fd..5115f3ae6 100644 --- a/lib/model/source/location.dart +++ b/lib/model/source/location.dart @@ -82,14 +82,14 @@ mixin LocationMixin on SourceBase { // - 652 calls (22%) when approximating to 2 decimal places (~1km - town or village) // cf https://en.wikipedia.org/wiki/Decimal_degrees#Precision final latLngFactor = pow(10, 2); - Tuple2 approximateLatLng(AvesEntry entry) { + Tuple2 approximateLatLng(AvesEntry entry) { final lat = entry.catalogMetadata?.latitude; final lng = entry.catalogMetadata?.longitude; if (lat == null || lng == null) return null; - return Tuple2((lat * latLngFactor).round(), (lng * latLngFactor).round()); + return Tuple2((lat * latLngFactor).round(), (lng * latLngFactor).round()); } - final knownLocations = {}; + final knownLocations = , AddressDetails>{}; byLocated[true]?.forEach((entry) => knownLocations.putIfAbsent(approximateLatLng(entry), () => entry.addressDetails)); stateNotifier.value = SourceState.locating; diff --git a/lib/services/geocoding_service.dart b/lib/services/geocoding_service.dart index 66612e96e..6ad6f23cf 100644 --- a/lib/services/geocoding_service.dart +++ b/lib/services/geocoding_service.dart @@ -15,6 +15,9 @@ class GeocodingService { 'latitude': coordinates.latitude, 'longitude': coordinates.longitude, 'locale': locale, + // we only really need one address, but sometimes the native geocoder + // returns nothing with `maxResults` of 1, but succeeds with `maxResults` of 2+ + 'maxResults': 2, }); return (result as List).cast().map((map) => Address.fromMap(map)).toList(); } on PlatformException catch (e) {