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
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
# TODO TLAD run `flutter format -l 1000 .` and fail if any
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Check code quality.
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: subosito/flutter-action@v1
|
||||
with:
|
||||
channel: stable
|
||||
flutter-version: '2.0.1'
|
||||
|
||||
- name: Clone the repository.
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Get packages for the Flutter project.
|
||||
run: flutter pub get
|
||||
|
||||
- name: Update the flutter version file.
|
||||
working-directory: ${{ github.workspace }}/scripts
|
||||
run: ./update_flutter_version.sh
|
||||
|
||||
- name: Static analysis.
|
||||
run: flutter analyze
|
||||
|
||||
- name: Unit tests.
|
||||
run: flutter test
|
||||
#name: Quality check
|
||||
#
|
||||
#on:
|
||||
# push:
|
||||
# branches:
|
||||
# - develop
|
||||
#
|
||||
## TODO TLAD run `flutter format -l 1000 .` and fail if any
|
||||
#
|
||||
#jobs:
|
||||
# build:
|
||||
# name: Check code quality.
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: subosito/flutter-action@v1
|
||||
# with:
|
||||
# channel: stable
|
||||
# flutter-version: '2.0.1'
|
||||
#
|
||||
# - name: Clone the repository.
|
||||
# uses: actions/checkout@v2
|
||||
#
|
||||
# - name: Get packages for the Flutter project.
|
||||
# run: flutter pub get
|
||||
#
|
||||
# - name: Update the flutter version file.
|
||||
# working-directory: ${{ github.workspace }}/scripts
|
||||
# run: ./update_flutter_version.sh
|
||||
#
|
||||
# - name: Static analysis.
|
||||
# run: flutter analyze
|
||||
#
|
||||
# - name: Unit tests.
|
||||
# run: flutter test
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package deckers.thibault.aves.channel.calls
|
||||
|
||||
import android.content.Context
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
@ -9,6 +8,7 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
|
||||
// as of 2021/03/10, geocoding packages exist but:
|
||||
// - `geocoder` is unmaintained
|
||||
|
@ -26,6 +26,7 @@ class GeocodingHandler(private val context: Context) : MethodCallHandler {
|
|||
private fun getAddress(call: MethodCall, result: MethodChannel.Result) {
|
||||
val latitude = call.argument<Number>("latitude")?.toDouble()
|
||||
val longitude = call.argument<Number>("longitude")?.toDouble()
|
||||
val localeString = call.argument<String>("locale")
|
||||
val maxResults = call.argument<Int>("maxResults") ?: 1
|
||||
if (latitude == null || longitude == null) {
|
||||
result.error("getAddress-args", "failed because of missing arguments", null)
|
||||
|
@ -37,9 +38,17 @@ class GeocodingHandler(private val context: Context) : MethodCallHandler {
|
|||
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 {
|
||||
geocoder!!.getFromLocation(latitude, longitude, maxResults) ?: ArrayList<Address>()
|
||||
geocoder!!.getFromLocation(latitude, longitude, maxResults) ?: ArrayList()
|
||||
} catch (e: Exception) {
|
||||
result.error("getAddress-exception", "failed to get address", e.message)
|
||||
return
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:aves/model/favourite_repo.dart';
|
|||
import 'package:aves/model/metadata.dart';
|
||||
import 'package:aves/model/metadata_db.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/image_file_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
|
||||
Future<void> locatePlace({@required bool background}) async {
|
||||
if (!hasGps || hasFineAddress) return;
|
||||
try {
|
||||
Future<List<Address>> call() => GeocodingService.getAddress(latLng);
|
||||
Future<List<Address>> call() => GeocodingService.getAddress(latLng, geocoderLocale);
|
||||
final addresses = await (background
|
||||
? servicePolicy.call(
|
||||
call,
|
||||
|
@ -510,7 +518,7 @@ class AvesEntry {
|
|||
if (!hasGps) return null;
|
||||
|
||||
try {
|
||||
final addresses = await GeocodingService.getAddress(latLng);
|
||||
final addresses = await GeocodingService.getAddress(latLng, geocoderLocale);
|
||||
if (addresses != null && addresses.isNotEmpty) {
|
||||
final address = addresses.first;
|
||||
return address.addressLine;
|
||||
|
|
|
@ -2,17 +2,19 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:latlong/latlong.dart';
|
||||
|
||||
class GeocodingService {
|
||||
static const platform = MethodChannel('deckers.thibault/aves/geocoding');
|
||||
|
||||
// geocoding requires Google Play Services
|
||||
static Future<List<Address>> getAddress(LatLng coordinates) async {
|
||||
static Future<List<Address>> getAddress(LatLng coordinates, String locale) async {
|
||||
try {
|
||||
final result = await platform.invokeMethod('getAddress', <String, dynamic>{
|
||||
'latitude': coordinates.latitude,
|
||||
'longitude': coordinates.longitude,
|
||||
'locale': locale,
|
||||
});
|
||||
return (result as List).cast<Map>().map((map) => Address.fromMap(map)).toList();
|
||||
} on PlatformException catch (e) {
|
||||
|
|
Loading…
Reference in a new issue