From 472c9e7160c98a02281ec56a22444b7475eba49e Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Wed, 14 Feb 2024 12:47:44 +0100 Subject: [PATCH 1/3] Implemented isPresent on Android --- geocoding_android/CHANGELOG.md | 4 ++++ .../java/com/baseflow/geocoding/Geocoding.java | 9 +++++++++ .../geocoding/MethodCallHandlerImpl.java | 8 ++++++++ .../lib/plugin_example/geocode_page.dart | 17 +++++++++++++++++ geocoding_android/lib/geocoding_android.dart | 15 +++++++++++++++ geocoding_android/pubspec.yaml | 2 +- 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/geocoding_android/CHANGELOG.md b/geocoding_android/CHANGELOG.md index e7f4b0b..8db9d40 100644 --- a/geocoding_android/CHANGELOG.md +++ b/geocoding_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.0 + + * Exposes isPresent() call that returns true if there is a geocoder implementation present that may return results. + ## 3.1.0 * Fixes deprecation build warnings. diff --git a/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java b/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java index 79ab29e..aade3be 100644 --- a/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java +++ b/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java @@ -36,6 +36,15 @@ void setLocaleIdentifier(@Nullable Locale locale) { this.locale = locale; } + /** + * Returns true if there is a geocoder implementation present that may return results. + * If true, there is still no guarantee that any individual geocoding attempt will succeed. + * + */ + boolean isPresent() { + return Geocoder.isPresent(); + } + /** * Returns a list of Address objects matching the supplied address string. * diff --git a/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java b/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java index b90d97d..eb2d15c 100644 --- a/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java +++ b/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java @@ -55,6 +55,9 @@ public void onMethodCall( case "placemarkFromCoordinates": onPlacemarkFromCoordinates(call, result); break; + case "isPresent": + onIsPresent(call, result); + break; default: result.notImplemented(); break; @@ -203,4 +206,9 @@ public void onError(String errorMessage) { } }); } + + private void onIsPresent(final MethodCall call, final Result result) { + boolean isPresent = geocoding.isPresent(); + result.success(isPresent); + } } diff --git a/geocoding_android/example/lib/plugin_example/geocode_page.dart b/geocoding_android/example/lib/plugin_example/geocode_page.dart index 504bc0a..989c4a3 100644 --- a/geocoding_android/example/lib/plugin_example/geocode_page.dart +++ b/geocoding_android/example/lib/plugin_example/geocode_page.dart @@ -154,6 +154,23 @@ class _GeocodeWidgetState extends State { }); }), ), + const Padding( + padding: EdgeInsets.only(top: 8), + ), + Center( + child: ElevatedButton( + child: Text('Is present'), + onPressed: () { + GeocodingAndroid().isPresent().then((isPresent) { + var output = isPresent + ? "Geocoder is present" + : "Geocoder is not present"; + setState(() { + _output = output; + }); + }); + }), + ), Expanded( child: SingleChildScrollView( child: Container( diff --git a/geocoding_android/lib/geocoding_android.dart b/geocoding_android/lib/geocoding_android.dart index 45797ce..41d1fb9 100644 --- a/geocoding_android/lib/geocoding_android.dart +++ b/geocoding_android/lib/geocoding_android.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ffi'; import 'package:flutter/services.dart'; import 'package:geocoding_platform_interface/geocoding_platform_interface.dart'; @@ -44,6 +45,20 @@ class GeocodingAndroid extends GeocodingPlatform { } } + @override + Future isPresent() async { + try { + final isPresent = await _channel.invokeMethod( + 'isPresent', + ); + + return isPresent; + } on PlatformException catch (e) { + _handlePlatformException(e); + rethrow; + } + } + @override Future> placemarkFromCoordinates( double latitude, diff --git a/geocoding_android/pubspec.yaml b/geocoding_android/pubspec.yaml index 750ddf9..e8ca303 100644 --- a/geocoding_android/pubspec.yaml +++ b/geocoding_android/pubspec.yaml @@ -1,6 +1,6 @@ name: geocoding_android description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features. -version: 3.1.0 +version: 3.2.0 repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_android issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues From 0dfbbc2ca5db2c31aa12abca871ad4469696af2e Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Wed, 14 Feb 2024 12:49:02 +0100 Subject: [PATCH 2/3] Implemented isPresent on the platform interface --- geocoding_platform_interface/CHANGELOG.md | 4 ++++ .../lib/src/geocoding_platform_interface.dart | 10 ++++++++++ geocoding_platform_interface/pubspec.yaml | 2 +- .../test/geocoding_platform_interface_test.dart | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/geocoding_platform_interface/CHANGELOG.md b/geocoding_platform_interface/CHANGELOG.md index c1942b1..d455e0b 100644 --- a/geocoding_platform_interface/CHANGELOG.md +++ b/geocoding_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.0 + +- Adds `isPresent` method to the platform interface. + ## 3.1.0 - Adds `placemarkFromAddress` method to the platform interface. diff --git a/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart b/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart index 415c05e..c046192 100644 --- a/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart +++ b/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart @@ -58,6 +58,16 @@ abstract class GeocodingPlatform extends PlatformInterface { 'locationFromAddress() has not been implementated.'); } + /// Returns true if there is a geocoder implementation present that may return results. + /// If true, there is still no guarantee that any individual geocoding attempt will succeed. + /// + /// + /// This method is only implemented on Android, calling this on iOS always + /// returns [true]. + Future isPresent() { + throw UnimplementedError('isPresent() has not been implementated.'); + } + /// Returns a list of [Placemark] instances found for the supplied /// coordinates. /// diff --git a/geocoding_platform_interface/pubspec.yaml b/geocoding_platform_interface/pubspec.yaml index d651b78..ffafc46 100644 --- a/geocoding_platform_interface/pubspec.yaml +++ b/geocoding_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the geocoding plugin. homepage: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 3.1.0 +version: 3.2.0 dependencies: flutter: diff --git a/geocoding_platform_interface/test/geocoding_platform_interface_test.dart b/geocoding_platform_interface/test/geocoding_platform_interface_test.dart index 34f75ae..ce0df16 100644 --- a/geocoding_platform_interface/test/geocoding_platform_interface_test.dart +++ b/geocoding_platform_interface/test/geocoding_platform_interface_test.dart @@ -51,6 +51,20 @@ void main() { ); }); + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of isPresent should throw unimplemented error', + () { + // Arrange + final geocodingPlatform = ExtendsGeocodingPlatform(); + + // Act & Assert + expect( + () => geocodingPlatform.isPresent(), + throwsUnimplementedError, + ); + }); + test( // ignore: lines_longer_than_80_chars 'Default implementation of placemarkFromCoordinates should throw unimplemented error', From 8f8d0f591aee57470ba27245044194345eea3917 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Thu, 15 Feb 2024 12:06:34 +0100 Subject: [PATCH 3/3] Added iOS implementation --- geocoding_ios/CHANGELOG.md | 4 ++++ .../example/lib/plugin_example/geocode_page.dart | 16 ++++++++++++++++ geocoding_ios/ios/Classes/GeocodingPlugin.m | 5 ++++- geocoding_ios/lib/geocoding_ios.dart | 14 ++++++++++++++ geocoding_ios/pubspec.yaml | 2 +- .../lib/src/geocoding_platform_interface.dart | 2 +- 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/geocoding_ios/CHANGELOG.md b/geocoding_ios/CHANGELOG.md index f7b75f2..3cf589b 100644 --- a/geocoding_ios/CHANGELOG.md +++ b/geocoding_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.0 + + * Implements `isPresent` that always returns true. + ## 2.2.0 * Updates `geocoding_platform_interface` to version 3.1.0. diff --git a/geocoding_ios/example/lib/plugin_example/geocode_page.dart b/geocoding_ios/example/lib/plugin_example/geocode_page.dart index cafe5af..1d99345 100644 --- a/geocoding_ios/example/lib/plugin_example/geocode_page.dart +++ b/geocoding_ios/example/lib/plugin_example/geocode_page.dart @@ -121,6 +121,22 @@ class _GeocodeWidgetState extends State { }); }), ), + const Padding( + padding: EdgeInsets.only(top: 8), + ), + Center( + child: ElevatedButton( + child: Text('Is present'), + onPressed: () { + GeocodingIOS().isPresent().then((isPresent) { + var output = isPresent + ? "Geocoder is present" + : "Geocoder is not present"; + setState(() { + _output = output; + }); + }); + })), Expanded( child: SingleChildScrollView( child: Container( diff --git a/geocoding_ios/ios/Classes/GeocodingPlugin.m b/geocoding_ios/ios/Classes/GeocodingPlugin.m index e66d2f0..a851d29 100644 --- a/geocoding_ios/ios/Classes/GeocodingPlugin.m +++ b/geocoding_ios/ios/Classes/GeocodingPlugin.m @@ -50,7 +50,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { message:errorDescription details:nil]); }]; - }else { + } else if ([@"isPresent" isEqualToString:call.method]) { + //There is no equal iOS implementation of the ANDROID Geocoder.isPresent. On iOS we assume that it is always present. + result(@YES); + } else { result(FlutterMethodNotImplemented); } } diff --git a/geocoding_ios/lib/geocoding_ios.dart b/geocoding_ios/lib/geocoding_ios.dart index 7ba83c7..0a26d3c 100644 --- a/geocoding_ios/lib/geocoding_ios.dart +++ b/geocoding_ios/lib/geocoding_ios.dart @@ -57,6 +57,20 @@ class GeocodingIOS extends GeocodingPlatform { return Placemark.fromMaps(placemarks); } + @override + Future isPresent() async { + try { + final isPresent = await _channel.invokeMethod( + 'isPresent', + ); + + return isPresent; + } on PlatformException catch (e) { + _handlePlatformException(e); + rethrow; + } + } + void _handlePlatformException(PlatformException platformException) { switch (platformException.code) { case 'NOT_FOUND': diff --git a/geocoding_ios/pubspec.yaml b/geocoding_ios/pubspec.yaml index 74cda0f..76057b8 100644 --- a/geocoding_ios/pubspec.yaml +++ b/geocoding_ios/pubspec.yaml @@ -1,6 +1,6 @@ name: geocoding_ios description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features. -version: 2.2.0 +version: 2.3.0 repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_ios issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues diff --git a/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart b/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart index c046192..ea75566 100644 --- a/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart +++ b/geocoding_platform_interface/lib/src/geocoding_platform_interface.dart @@ -62,7 +62,7 @@ abstract class GeocodingPlatform extends PlatformInterface { /// If true, there is still no guarantee that any individual geocoding attempt will succeed. /// /// - /// This method is only implemented on Android, calling this on iOS always + /// This method is only intended on Android, calling this on iOS always /// returns [true]. Future isPresent() { throw UnimplementedError('isPresent() has not been implementated.');