diff --git a/geocoding_ios/CHANGELOG.md b/geocoding_ios/CHANGELOG.md index 3cf589b..1fdf8ca 100644 --- a/geocoding_ios/CHANGELOG.md +++ b/geocoding_ios/CHANGELOG.md @@ -1,11 +1,19 @@ +## 3.0.0 + +* **BREAKING CHANGES**: + * Removes the `localeIdentifier` argument from all methods. Use method `setLocaleIdentifier` to configure the locale. + * Removes old iOS version checks and expects iOS 12 and above. (minimal iOS version is 12 per 2.2.0) +* Fixes to configure the locale. +* Updated example app with locale example. + ## 2.3.0 - * Implements `isPresent` that always returns true. +* Implements `isPresent` that always returns true. ## 2.2.0 - * Updates `geocoding_platform_interface` to version 3.1.0. - * Updates minimal iOS version of the example application to 12. +* Updates `geocoding_platform_interface` to version 3.1.0. +* Updates minimal iOS version of the example application to 12. ## 2.1.1 diff --git a/geocoding_ios/example/lib/plugin_example/geocode_page.dart b/geocoding_ios/example/lib/plugin_example/geocode_page.dart index 1d99345..5fff783 100644 --- a/geocoding_ios/example/lib/plugin_example/geocode_page.dart +++ b/geocoding_ios/example/lib/plugin_example/geocode_page.dart @@ -14,6 +14,7 @@ class _GeocodeWidgetState extends State { final TextEditingController _latitudeController = TextEditingController(); final TextEditingController _longitudeController = TextEditingController(); String _output = ''; + GeocodingIOS _geocodingIOS = GeocodingIOS(); @override void initState() { @@ -74,7 +75,7 @@ class _GeocodeWidgetState extends State { final latitude = double.parse(_latitudeController.text); final longitude = double.parse(_longitudeController.text); - GeocodingIOS() + _geocodingIOS .placemarkFromCoordinates(latitude, longitude) .then((placemarks) { var output = 'No results found.'; @@ -107,7 +108,7 @@ class _GeocodeWidgetState extends State { child: ElevatedButton( child: Text('Look up location'), onPressed: () { - GeocodingIOS() + _geocodingIOS .locationFromAddress(_addressController.text) .then((locations) { var output = 'No results found.'; @@ -128,7 +129,7 @@ class _GeocodeWidgetState extends State { child: ElevatedButton( child: Text('Is present'), onPressed: () { - GeocodingIOS().isPresent().then((isPresent) { + _geocodingIOS.isPresent().then((isPresent) { var output = isPresent ? "Geocoder is present" : "Geocoder is not present"; @@ -137,6 +138,31 @@ class _GeocodeWidgetState extends State { }); }); })), + const Padding( + padding: EdgeInsets.only(top: 8), + ), + Center( + child: ElevatedButton( + child: Text('Set locale en_US'), + onPressed: () { + _geocodingIOS.setLocaleIdentifier("en_US").then((_) { + setState(() {}); + }); + })), + const Padding( + padding: EdgeInsets.only(top: 8), + ), + Center( + child: ElevatedButton( + child: Text('Set locale nl_NL'), + onPressed: () { + _geocodingIOS.setLocaleIdentifier("nl_NL").then((_) { + setState(() {}); + }); + })), + const Padding( + padding: EdgeInsets.only(top: 8), + ), Expanded( child: SingleChildScrollView( child: Container( diff --git a/geocoding_ios/ios/Classes/GeocodingHandler.m b/geocoding_ios/ios/Classes/GeocodingHandler.m index 504231c..3e12635 100644 --- a/geocoding_ios/ios/Classes/GeocodingHandler.m +++ b/geocoding_ios/ios/Classes/GeocodingHandler.m @@ -31,42 +31,16 @@ - (void) geocodeFromAddress: (NSString *)address return; } - if (@available(iOS 11.0, *)) { - [_geocoder geocodeAddressString:address - inRegion:nil - preferredLocale:locale - completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) - { - [GeocodingHandler completeGeocodingWith:placemarks - error:error - success:successHandler - failure:failureHandler]; - }]; - } else { - NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; - NSArray *defaultLanguages; - - if (locale != nil) { - defaultLanguages = [standardUserDefaults arrayForKey:@"AppleLanguages"]; - [standardUserDefaults setValue:[GeocodingHandler languageCode:locale] - forKey:@"AppleLanguages"]; - } - - [_geocoder geocodeAddressString:address - completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) { - - [GeocodingHandler completeGeocodingWith:placemarks - error:error - success:successHandler - failure:failureHandler]; - - if (locale != nil) { - [standardUserDefaults setValue:defaultLanguages - forKey:@"AppleLanguages"]; - } - }]; - } - + [_geocoder geocodeAddressString:address + inRegion:nil + preferredLocale:locale + completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) + { + [GeocodingHandler completeGeocodingWith:placemarks + error:error + success:successHandler + failure:failureHandler]; + }]; return; } @@ -74,39 +48,14 @@ - (void) geocodeToAddress: (CLLocation *)location locale: (NSLocale *)locale success: (GeocodingSuccess)successHandler failure: (GeocodingFailure)failureHandler { - - if (@available(iOS 11.0, *)) { - [_geocoder reverseGeocodeLocation:location - preferredLocale:locale - completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) { - [GeocodingHandler completeGeocodingWith:placemarks - error:error - success:successHandler - failure:failureHandler]; - }]; - - } else { - NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; - NSArray *defaultLanguages; - - if (locale != nil) { - defaultLanguages = [standardUserDefaults arrayForKey:@"AppleLanguages"]; - [standardUserDefaults setValue:[GeocodingHandler languageCode:locale] - forKey:@"AppleLanguages"]; - } - - [_geocoder reverseGeocodeLocation:location - completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) { - [GeocodingHandler completeGeocodingWith:placemarks - error:error - success:successHandler - failure:failureHandler]; - - if (locale != nil) { - [standardUserDefaults setValue:defaultLanguages forKey:@"AppleLanguages"]; - } - }]; - } + [_geocoder reverseGeocodeLocation:location + preferredLocale:locale + completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) { + [GeocodingHandler completeGeocodingWith:placemarks + error:error + success:successHandler + failure:failureHandler]; + }]; } + (void) completeGeocodingWith: (NSArray *) placemarks @@ -128,10 +77,6 @@ + (void) completeGeocodingWith: (NSArray *) placemarks + (NSString *) languageCode:(NSLocale *)locale { - if (@available(iOS 10.0, *)) { - return [locale languageCode]; - } else { - return [[locale localeIdentifier] substringToIndex:2]; - } + return [locale languageCode]; } @end diff --git a/geocoding_ios/lib/geocoding_ios.dart b/geocoding_ios/lib/geocoding_ios.dart index 3c3d290..234dbb6 100644 --- a/geocoding_ios/lib/geocoding_ios.dart +++ b/geocoding_ios/lib/geocoding_ios.dart @@ -5,24 +5,30 @@ import 'package:geocoding_platform_interface/geocoding_platform_interface.dart'; const MethodChannel _channel = MethodChannel('flutter.baseflow.com/geocoding'); -/// An implementation of [GeocodingPlatform] for Android. +/// An implementation of [GeocodingPlatform] for iOS. class GeocodingIOS extends GeocodingPlatform { /// Registers this class as the default instance of [GeocodingPlatform]. static void registerWith() { GeocodingPlatform.instance = GeocodingIOS(); } + String? _localeIdentifier; + + @override + Future setLocaleIdentifier( + String localeIdentifier, + ) async { + _localeIdentifier = localeIdentifier; + } + @override - Future> locationFromAddress( - String address, { - String? localeIdentifier, - }) async { + Future> locationFromAddress(String address) async { final parameters = { 'address': address, }; - if (localeIdentifier != null) { - parameters['localeIdentifier'] = localeIdentifier; + if (_localeIdentifier != null) { + parameters['localeIdentifier'] = _localeIdentifier!; } try { final placemarks = await _channel.invokeMethod( @@ -40,16 +46,15 @@ class GeocodingIOS extends GeocodingPlatform { @override Future> placemarkFromCoordinates( double latitude, - double longitude, { - String? localeIdentifier, - }) async { + double longitude, + ) async { final parameters = { 'latitude': latitude, 'longitude': longitude, }; - if (localeIdentifier != null) { - parameters['localeIdentifier'] = localeIdentifier; + if (_localeIdentifier != null) { + parameters['localeIdentifier'] = _localeIdentifier!; } final placemarks = diff --git a/geocoding_ios/pubspec.yaml b/geocoding_ios/pubspec.yaml index c867ab3..b979d26 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.3.0 +version: 3.0.0 repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_ios issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues