geocoding with locale
removed check workflow while on flutter master
This commit is contained in:
parent
755cc05827
commit
87fb9c73e1
4 changed files with 59 additions and 40 deletions
68
.github/workflows/check.yml
vendored
68
.github/workflows/check.yml
vendored
|
@ -1,34 +1,34 @@
|
||||||
name: Quality check
|
#name: Quality check
|
||||||
|
#
|
||||||
on:
|
#on:
|
||||||
push:
|
# push:
|
||||||
branches:
|
# branches:
|
||||||
- develop
|
# - develop
|
||||||
|
#
|
||||||
# TODO TLAD run `flutter format -l 1000 .` and fail if any
|
## TODO TLAD run `flutter format -l 1000 .` and fail if any
|
||||||
|
#
|
||||||
jobs:
|
#jobs:
|
||||||
build:
|
# build:
|
||||||
name: Check code quality.
|
# name: Check code quality.
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
steps:
|
# steps:
|
||||||
- uses: subosito/flutter-action@v1
|
# - uses: subosito/flutter-action@v1
|
||||||
with:
|
# with:
|
||||||
channel: stable
|
# channel: stable
|
||||||
flutter-version: '2.0.1'
|
# flutter-version: '2.0.1'
|
||||||
|
#
|
||||||
- name: Clone the repository.
|
# - name: Clone the repository.
|
||||||
uses: actions/checkout@v2
|
# uses: actions/checkout@v2
|
||||||
|
#
|
||||||
- name: Get packages for the Flutter project.
|
# - name: Get packages for the Flutter project.
|
||||||
run: flutter pub get
|
# run: flutter pub get
|
||||||
|
#
|
||||||
- name: Update the flutter version file.
|
# - name: Update the flutter version file.
|
||||||
working-directory: ${{ github.workspace }}/scripts
|
# working-directory: ${{ github.workspace }}/scripts
|
||||||
run: ./update_flutter_version.sh
|
# run: ./update_flutter_version.sh
|
||||||
|
#
|
||||||
- name: Static analysis.
|
# - name: Static analysis.
|
||||||
run: flutter analyze
|
# run: flutter analyze
|
||||||
|
#
|
||||||
- name: Unit tests.
|
# - name: Unit tests.
|
||||||
run: flutter test
|
# run: flutter test
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package deckers.thibault.aves.channel.calls
|
package deckers.thibault.aves.channel.calls
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.location.Address
|
|
||||||
import android.location.Geocoder
|
import android.location.Geocoder
|
||||||
import io.flutter.plugin.common.MethodCall
|
import io.flutter.plugin.common.MethodCall
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
@ -9,6 +8,7 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
// as of 2021/03/10, geocoding packages exist but:
|
// as of 2021/03/10, geocoding packages exist but:
|
||||||
// - `geocoder` is unmaintained
|
// - `geocoder` is unmaintained
|
||||||
|
@ -26,6 +26,7 @@ class GeocodingHandler(private val context: Context) : MethodCallHandler {
|
||||||
private fun getAddress(call: MethodCall, result: MethodChannel.Result) {
|
private fun getAddress(call: MethodCall, result: MethodChannel.Result) {
|
||||||
val latitude = call.argument<Number>("latitude")?.toDouble()
|
val latitude = call.argument<Number>("latitude")?.toDouble()
|
||||||
val longitude = call.argument<Number>("longitude")?.toDouble()
|
val longitude = call.argument<Number>("longitude")?.toDouble()
|
||||||
|
val localeString = call.argument<String>("locale")
|
||||||
val maxResults = call.argument<Int>("maxResults") ?: 1
|
val maxResults = call.argument<Int>("maxResults") ?: 1
|
||||||
if (latitude == null || longitude == null) {
|
if (latitude == null || longitude == null) {
|
||||||
result.error("getAddress-args", "failed because of missing arguments", null)
|
result.error("getAddress-args", "failed because of missing arguments", null)
|
||||||
|
@ -37,9 +38,17 @@ class GeocodingHandler(private val context: Context) : MethodCallHandler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
geocoder = geocoder ?: Geocoder(context)
|
geocoder = geocoder ?: if (localeString != null) {
|
||||||
|
val split = localeString.split("_")
|
||||||
|
val language = split[0]
|
||||||
|
val country = if (split.size > 1) split[1] else ""
|
||||||
|
Geocoder(context, Locale(language, country))
|
||||||
|
} else {
|
||||||
|
Geocoder(context)
|
||||||
|
}
|
||||||
|
|
||||||
val addresses = try {
|
val addresses = try {
|
||||||
geocoder!!.getFromLocation(latitude, longitude, maxResults) ?: ArrayList<Address>()
|
geocoder!!.getFromLocation(latitude, longitude, maxResults) ?: ArrayList()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
result.error("getAddress-exception", "failed to get address", e.message)
|
result.error("getAddress-exception", "failed to get address", e.message)
|
||||||
return
|
return
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:aves/model/favourite_repo.dart';
|
||||||
import 'package:aves/model/metadata.dart';
|
import 'package:aves/model/metadata.dart';
|
||||||
import 'package:aves/model/metadata_db.dart';
|
import 'package:aves/model/metadata_db.dart';
|
||||||
import 'package:aves/model/multipage.dart';
|
import 'package:aves/model/multipage.dart';
|
||||||
|
import 'package:aves/model/settings/settings.dart';
|
||||||
import 'package:aves/services/geocoding_service.dart';
|
import 'package:aves/services/geocoding_service.dart';
|
||||||
import 'package:aves/services/image_file_service.dart';
|
import 'package:aves/services/image_file_service.dart';
|
||||||
import 'package:aves/services/metadata_service.dart';
|
import 'package:aves/services/metadata_service.dart';
|
||||||
|
@ -475,11 +476,18 @@ class AvesEntry {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _geocoderLocale;
|
||||||
|
|
||||||
|
String get geocoderLocale {
|
||||||
|
_geocoderLocale ??= (settings.locale ?? WidgetsBinding.instance.window.locale).toString();
|
||||||
|
return _geocoderLocale;
|
||||||
|
}
|
||||||
|
|
||||||
// full reverse geocoding, requiring Play Services and some connectivity
|
// full reverse geocoding, requiring Play Services and some connectivity
|
||||||
Future<void> locatePlace({@required bool background}) async {
|
Future<void> locatePlace({@required bool background}) async {
|
||||||
if (!hasGps || hasFineAddress) return;
|
if (!hasGps || hasFineAddress) return;
|
||||||
try {
|
try {
|
||||||
Future<List<Address>> call() => GeocodingService.getAddress(latLng);
|
Future<List<Address>> call() => GeocodingService.getAddress(latLng, geocoderLocale);
|
||||||
final addresses = await (background
|
final addresses = await (background
|
||||||
? servicePolicy.call(
|
? servicePolicy.call(
|
||||||
call,
|
call,
|
||||||
|
@ -510,7 +518,7 @@ class AvesEntry {
|
||||||
if (!hasGps) return null;
|
if (!hasGps) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final addresses = await GeocodingService.getAddress(latLng);
|
final addresses = await GeocodingService.getAddress(latLng, geocoderLocale);
|
||||||
if (addresses != null && addresses.isNotEmpty) {
|
if (addresses != null && addresses.isNotEmpty) {
|
||||||
final address = addresses.first;
|
final address = addresses.first;
|
||||||
return address.addressLine;
|
return address.addressLine;
|
||||||
|
|
|
@ -2,17 +2,19 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:latlong/latlong.dart';
|
import 'package:latlong/latlong.dart';
|
||||||
|
|
||||||
class GeocodingService {
|
class GeocodingService {
|
||||||
static const platform = MethodChannel('deckers.thibault/aves/geocoding');
|
static const platform = MethodChannel('deckers.thibault/aves/geocoding');
|
||||||
|
|
||||||
// geocoding requires Google Play Services
|
// geocoding requires Google Play Services
|
||||||
static Future<List<Address>> getAddress(LatLng coordinates) async {
|
static Future<List<Address>> getAddress(LatLng coordinates, String locale) async {
|
||||||
try {
|
try {
|
||||||
final result = await platform.invokeMethod('getAddress', <String, dynamic>{
|
final result = await platform.invokeMethod('getAddress', <String, dynamic>{
|
||||||
'latitude': coordinates.latitude,
|
'latitude': coordinates.latitude,
|
||||||
'longitude': coordinates.longitude,
|
'longitude': coordinates.longitude,
|
||||||
|
'locale': locale,
|
||||||
});
|
});
|
||||||
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