Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Commit 214da3d

Browse files
committed
When a geocode is in progress on iOS, let it finish, and mark our new geocode request as unavailable. This will let it potentially fallback to using the google maps geocoder. This lets parallel geocodes work on iOS when called from multiple unrelated async functions.
1 parent a5710ec commit 214da3d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ both iOS and Android will return the following object:
131131
## Notes
132132

133133
### iOS
134-
iOS does not allow sending multiple geocoding requests simultaneously.
134+
iOS does not allow sending multiple geocoding requests simultaneously, unless you enable the fallbackToGoogle to handle the parallel calls when an native iOS request is active.
135135

136136
### Android
137137
geocoding may not work on older android devices (4.1) and will not work if Google play services are not available.

ios/RNGeocoder/RNGeocoder.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ @implementation RNGeocoder
3030
self.geocoder = [[CLGeocoder alloc] init];
3131
}
3232

33-
[self.geocoder cancelGeocode];
33+
if (self.geocoder.geocoding) {
34+
return reject(@"NOT_AVAILABLE", @"geocodePosition busy", nil);
35+
}
3436

3537
[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
3638

@@ -55,16 +57,18 @@ @implementation RNGeocoder
5557
self.geocoder = [[CLGeocoder alloc] init];
5658
}
5759

58-
[self.geocoder cancelGeocode];
60+
if (self.geocoder.geocoding) {
61+
return reject(@"NOT_AVAILABLE", @"geocodeAddress busy", nil);
62+
}
5963

6064
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
6165

6266
if (error) {
6367
if (placemarks.count == 0) {
64-
return reject(@"NOT_FOUND", @"geocodePosition failed", error);
68+
return reject(@"NOT_FOUND", @"geocodeAddress failed", error);
6569
}
6670

67-
return reject(@"ERROR", @"geocodePosition failed", error);
71+
return reject(@"ERROR", @"geocodeAddress failed", error);
6872
}
6973

7074
resolve([self placemarksToDictionary:placemarks]);

0 commit comments

Comments
 (0)