Skip to content

Commit dfbbdff

Browse files
chore(android): set location API as a default provider (#214)
1 parent 741a353 commit dfbbdff

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Supports TurboModules ⚡️ and legacy React Native architecture.
88

99
Fully compatible with TypeScript.
1010

11-
Uses modern [Play Services Location API](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient.html) and falls back to legacy [Android Location API](https://developer.android.com/reference/android/location/Location) if PlayServices aren't available.
11+
Supports modern [Play Services Location API](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient.html).
1212

1313

1414
## Supported platforms
@@ -139,7 +139,7 @@ Supported options:
139139

140140
* `skipPermissionRequests` (boolean) - Defaults to `false`. If `true`, you must request permissions before using Geolocation APIs.
141141
* `authorizationLevel` (string, iOS-only) - Either `"whenInUse"`, `"always"`, or `"auto"`. Changes whether the user will be asked to give "always" or "when in use" location services permission. Any other value or `auto` will use the default behaviour, where the permission level is based on the contents of your `Info.plist`.
142-
* `locationProvider` (string, Android-only) - Either `"playServices"`, `"android"`, or `"auto"`. Determines wether to use `Google’s Location Services API` or `Android’s Location API`. The `"auto"` mode defaults to `playServices`, and falls back to Android's Location API if play services aren't available.
142+
* `locationProvider` (string, Android-only) - Either `"playServices"`, `"android"`, or `"auto"`. Determines wether to use `Google’s Location Services API` or `Android’s Location API`. The `"auto"` mode defaults to `android`, and falls back to Android's Location API if play services aren't available.
143143

144144
---
145145

android/src/main/java/com/reactnativecommunity/geolocation/GeolocationModule.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ public class GeolocationModule extends ReactContextBaseJavaModule {
3434
public GeolocationModule(ReactApplicationContext reactContext) {
3535
super(reactContext);
3636
mConfiguration = Configuration.getDefault();
37-
GoogleApiAvailability availability = new GoogleApiAvailability();
38-
if (availability.isGooglePlayServicesAvailable(reactContext.getApplicationContext()) == ConnectionResult.SUCCESS) {
39-
mLocationManager = new PlayServicesLocationManager(reactContext);
40-
} else {
41-
mLocationManager = new AndroidLocationManager(reactContext);
42-
}
43-
37+
mLocationManager = new AndroidLocationManager(reactContext);
4438
}
4539

4640
@Override
@@ -54,10 +48,14 @@ public void setConfiguration(ReadableMap config) {
5448
}
5549

5650
private void onConfigurationChange(Configuration config) {
51+
ReactApplicationContext reactContext = mLocationManager.mReactContext;
5752
if (Objects.equals(config.locationProvider, "android") && mLocationManager instanceof PlayServicesLocationManager) {
58-
mLocationManager = new AndroidLocationManager(mLocationManager.mReactContext);
53+
mLocationManager = new AndroidLocationManager(reactContext);
5954
} else if (Objects.equals(config.locationProvider, "playServices") && mLocationManager instanceof AndroidLocationManager) {
60-
mLocationManager = new PlayServicesLocationManager(mLocationManager.mReactContext);
55+
GoogleApiAvailability availability = new GoogleApiAvailability();
56+
if (availability.isGooglePlayServicesAvailable(reactContext.getApplicationContext()) == ConnectionResult.SUCCESS) {
57+
mLocationManager = new PlayServicesLocationManager(reactContext);
58+
}
6159
}
6260
}
6361

0 commit comments

Comments
 (0)