fixed geocoding params
This commit is contained in:
parent
cef6c8b479
commit
30e8521aaa
2 changed files with 6 additions and 3 deletions
|
@ -82,14 +82,14 @@ mixin LocationMixin on SourceBase {
|
||||||
// - 652 calls (22%) when approximating to 2 decimal places (~1km - town or village)
|
// - 652 calls (22%) when approximating to 2 decimal places (~1km - town or village)
|
||||||
// cf https://en.wikipedia.org/wiki/Decimal_degrees#Precision
|
// cf https://en.wikipedia.org/wiki/Decimal_degrees#Precision
|
||||||
final latLngFactor = pow(10, 2);
|
final latLngFactor = pow(10, 2);
|
||||||
Tuple2 approximateLatLng(AvesEntry entry) {
|
Tuple2<int, int> approximateLatLng(AvesEntry entry) {
|
||||||
final lat = entry.catalogMetadata?.latitude;
|
final lat = entry.catalogMetadata?.latitude;
|
||||||
final lng = entry.catalogMetadata?.longitude;
|
final lng = entry.catalogMetadata?.longitude;
|
||||||
if (lat == null || lng == null) return null;
|
if (lat == null || lng == null) return null;
|
||||||
return Tuple2((lat * latLngFactor).round(), (lng * latLngFactor).round());
|
return Tuple2<int, int>((lat * latLngFactor).round(), (lng * latLngFactor).round());
|
||||||
}
|
}
|
||||||
|
|
||||||
final knownLocations = <Tuple2, AddressDetails>{};
|
final knownLocations = <Tuple2<int, int>, AddressDetails>{};
|
||||||
byLocated[true]?.forEach((entry) => knownLocations.putIfAbsent(approximateLatLng(entry), () => entry.addressDetails));
|
byLocated[true]?.forEach((entry) => knownLocations.putIfAbsent(approximateLatLng(entry), () => entry.addressDetails));
|
||||||
|
|
||||||
stateNotifier.value = SourceState.locating;
|
stateNotifier.value = SourceState.locating;
|
||||||
|
|
|
@ -15,6 +15,9 @@ class GeocodingService {
|
||||||
'latitude': coordinates.latitude,
|
'latitude': coordinates.latitude,
|
||||||
'longitude': coordinates.longitude,
|
'longitude': coordinates.longitude,
|
||||||
'locale': locale,
|
'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((map) => Address.fromMap(map)).toList();
|
return (result as List).cast<Map>().map((map) => Address.fromMap(map)).toList();
|
||||||
} on PlatformException catch (e) {
|
} on PlatformException catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue