Skip to content

Commit ebef75c

Browse files
committed
Merge branch 'main' into feature/208-add-locale-to-example-android
2 parents cb6849f + 6668457 commit ebef75c

File tree

9 files changed

+84
-96
lines changed

9 files changed

+84
-96
lines changed

geocoding_ios/CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
## 3.0.0
2+
3+
* **BREAKING CHANGES**:
4+
* Removes the `localeIdentifier` argument from all methods. Use method `setLocaleIdentifier` to configure the locale.
5+
* Removes old iOS version checks and expects iOS 12 and above. (minimal iOS version is 12 per 2.2.0)
6+
* Fixes to configure the locale.
7+
* Updated example app with locale example.
8+
19
## 2.3.0
210

3-
* Implements `isPresent` that always returns true.
11+
* Implements `isPresent` that always returns true.
412

513
## 2.2.0
614

7-
* Updates `geocoding_platform_interface` to version 3.1.0.
8-
* Updates minimal iOS version of the example application to 12.
15+
* Updates `geocoding_platform_interface` to version 3.1.0.
16+
* Updates minimal iOS version of the example application to 12.
917

1018
## 2.1.1
1119

geocoding_ios/example/lib/plugin_example/geocode_page.dart

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
1414
final TextEditingController _latitudeController = TextEditingController();
1515
final TextEditingController _longitudeController = TextEditingController();
1616
String _output = '';
17+
GeocodingIOS _geocodingIOS = GeocodingIOS();
1718

1819
@override
1920
void initState() {
@@ -74,7 +75,7 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
7475
final latitude = double.parse(_latitudeController.text);
7576
final longitude = double.parse(_longitudeController.text);
7677

77-
GeocodingIOS()
78+
_geocodingIOS
7879
.placemarkFromCoordinates(latitude, longitude)
7980
.then((placemarks) {
8081
var output = 'No results found.';
@@ -107,7 +108,7 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
107108
child: ElevatedButton(
108109
child: Text('Look up location'),
109110
onPressed: () {
110-
GeocodingIOS()
111+
_geocodingIOS
111112
.locationFromAddress(_addressController.text)
112113
.then((locations) {
113114
var output = 'No results found.';
@@ -128,7 +129,7 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
128129
child: ElevatedButton(
129130
child: Text('Is present'),
130131
onPressed: () {
131-
GeocodingIOS().isPresent().then((isPresent) {
132+
_geocodingIOS.isPresent().then((isPresent) {
132133
var output = isPresent
133134
? "Geocoder is present"
134135
: "Geocoder is not present";
@@ -137,6 +138,31 @@ class _GeocodeWidgetState extends State<GeocodeWidget> {
137138
});
138139
});
139140
})),
141+
const Padding(
142+
padding: EdgeInsets.only(top: 8),
143+
),
144+
Center(
145+
child: ElevatedButton(
146+
child: Text('Set locale en_US'),
147+
onPressed: () {
148+
_geocodingIOS.setLocaleIdentifier("en_US").then((_) {
149+
setState(() {});
150+
});
151+
})),
152+
const Padding(
153+
padding: EdgeInsets.only(top: 8),
154+
),
155+
Center(
156+
child: ElevatedButton(
157+
child: Text('Set locale nl_NL'),
158+
onPressed: () {
159+
_geocodingIOS.setLocaleIdentifier("nl_NL").then((_) {
160+
setState(() {});
161+
});
162+
})),
163+
const Padding(
164+
padding: EdgeInsets.only(top: 8),
165+
),
140166
Expanded(
141167
child: SingleChildScrollView(
142168
child: Container(

geocoding_ios/ios/Classes/GeocodingHandler.m

Lines changed: 19 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,82 +31,31 @@ - (void) geocodeFromAddress: (NSString *)address
3131
return;
3232
}
3333

34-
if (@available(iOS 11.0, *)) {
35-
[_geocoder geocodeAddressString:address
36-
inRegion:nil
37-
preferredLocale:locale
38-
completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error)
39-
{
40-
[GeocodingHandler completeGeocodingWith:placemarks
41-
error:error
42-
success:successHandler
43-
failure:failureHandler];
44-
}];
45-
} else {
46-
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
47-
NSArray<NSString * > *defaultLanguages;
48-
49-
if (locale != nil) {
50-
defaultLanguages = [standardUserDefaults arrayForKey:@"AppleLanguages"];
51-
[standardUserDefaults setValue:[GeocodingHandler languageCode:locale]
52-
forKey:@"AppleLanguages"];
53-
}
54-
55-
[_geocoder geocodeAddressString:address
56-
completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) {
57-
58-
[GeocodingHandler completeGeocodingWith:placemarks
59-
error:error
60-
success:successHandler
61-
failure:failureHandler];
62-
63-
if (locale != nil) {
64-
[standardUserDefaults setValue:defaultLanguages
65-
forKey:@"AppleLanguages"];
66-
}
67-
}];
68-
}
69-
34+
[_geocoder geocodeAddressString:address
35+
inRegion:nil
36+
preferredLocale:locale
37+
completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error)
38+
{
39+
[GeocodingHandler completeGeocodingWith:placemarks
40+
error:error
41+
success:successHandler
42+
failure:failureHandler];
43+
}];
7044
return;
7145
}
7246

7347
- (void) geocodeToAddress: (CLLocation *)location
7448
locale: (NSLocale *)locale
7549
success: (GeocodingSuccess)successHandler
7650
failure: (GeocodingFailure)failureHandler {
77-
78-
if (@available(iOS 11.0, *)) {
79-
[_geocoder reverseGeocodeLocation:location
80-
preferredLocale:locale
81-
completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) {
82-
[GeocodingHandler completeGeocodingWith:placemarks
83-
error:error
84-
success:successHandler
85-
failure:failureHandler];
86-
}];
87-
88-
} else {
89-
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
90-
NSArray<NSString * > *defaultLanguages;
91-
92-
if (locale != nil) {
93-
defaultLanguages = [standardUserDefaults arrayForKey:@"AppleLanguages"];
94-
[standardUserDefaults setValue:[GeocodingHandler languageCode:locale]
95-
forKey:@"AppleLanguages"];
96-
}
97-
98-
[_geocoder reverseGeocodeLocation:location
99-
completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) {
100-
[GeocodingHandler completeGeocodingWith:placemarks
101-
error:error
102-
success:successHandler
103-
failure:failureHandler];
104-
105-
if (locale != nil) {
106-
[standardUserDefaults setValue:defaultLanguages forKey:@"AppleLanguages"];
107-
}
108-
}];
109-
}
51+
[_geocoder reverseGeocodeLocation:location
52+
preferredLocale:locale
53+
completionHandler:^(NSArray< CLPlacemark *> *__nullable placemarks, NSError *__nullable error) {
54+
[GeocodingHandler completeGeocodingWith:placemarks
55+
error:error
56+
success:successHandler
57+
failure:failureHandler];
58+
}];
11059
}
11160

11261
+ (void) completeGeocodingWith: (NSArray<CLPlacemark *> *) placemarks
@@ -128,10 +77,6 @@ + (void) completeGeocodingWith: (NSArray<CLPlacemark *> *) placemarks
12877

12978

13079
+ (NSString *) languageCode:(NSLocale *)locale {
131-
if (@available(iOS 10.0, *)) {
132-
return [locale languageCode];
133-
} else {
134-
return [[locale localeIdentifier] substringToIndex:2];
135-
}
80+
return [locale languageCode];
13681
}
13782
@end

geocoding_ios/lib/geocoding_ios.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@ import 'package:geocoding_platform_interface/geocoding_platform_interface.dart';
55

66
const MethodChannel _channel = MethodChannel('flutter.baseflow.com/geocoding');
77

8-
/// An implementation of [GeocodingPlatform] for Android.
8+
/// An implementation of [GeocodingPlatform] for iOS.
99
class GeocodingIOS extends GeocodingPlatform {
1010
/// Registers this class as the default instance of [GeocodingPlatform].
1111
static void registerWith() {
1212
GeocodingPlatform.instance = GeocodingIOS();
1313
}
1414

15+
String? _localeIdentifier;
16+
17+
@override
18+
Future<void> setLocaleIdentifier(
19+
String localeIdentifier,
20+
) async {
21+
_localeIdentifier = localeIdentifier;
22+
}
23+
1524
@override
16-
Future<List<Location>> locationFromAddress(
17-
String address, {
18-
String? localeIdentifier,
19-
}) async {
25+
Future<List<Location>> locationFromAddress(String address) async {
2026
final parameters = <String, String>{
2127
'address': address,
2228
};
2329

24-
if (localeIdentifier != null) {
25-
parameters['localeIdentifier'] = localeIdentifier;
30+
if (_localeIdentifier != null) {
31+
parameters['localeIdentifier'] = _localeIdentifier!;
2632
}
2733
try {
2834
final placemarks = await _channel.invokeMethod(
@@ -40,16 +46,15 @@ class GeocodingIOS extends GeocodingPlatform {
4046
@override
4147
Future<List<Placemark>> placemarkFromCoordinates(
4248
double latitude,
43-
double longitude, {
44-
String? localeIdentifier,
45-
}) async {
49+
double longitude,
50+
) async {
4651
final parameters = <String, dynamic>{
4752
'latitude': latitude,
4853
'longitude': longitude,
4954
};
5055

51-
if (localeIdentifier != null) {
52-
parameters['localeIdentifier'] = localeIdentifier;
56+
if (_localeIdentifier != null) {
57+
parameters['localeIdentifier'] = _localeIdentifier!;
5358
}
5459

5560
final placemarks =

geocoding_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: geocoding_ios
22
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
3-
version: 2.3.0
3+
version: 3.0.0
44
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_ios
55
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues
66

geocoding_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.2.1
2+
3+
- Fixed analysis warnings from `flutter analyse`.
4+
15
## 3.2.0
26

37
- Adds `isPresent` method to the platform interface.

geocoding_platform_interface/lib/src/models/location.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Location {
2828
final DateTime timestamp;
2929

3030
@override
31-
bool operator ==(dynamic other) =>
31+
bool operator ==(Object other) =>
3232
other is Location &&
3333
other.latitude == latitude &&
3434
other.longitude == longitude &&

geocoding_platform_interface/lib/src/models/placemark.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Placemark {
6868
final String? subThoroughfare;
6969

7070
@override
71-
bool operator ==(dynamic other) =>
71+
bool operator ==(Object other) =>
7272
other is Placemark &&
7373
other.administrativeArea == administrativeArea &&
7474
other.country == country &&

geocoding_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the geocoding plugin.
33
homepage: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 3.2.0
6+
version: 3.2.1
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)