Skip to content

Commit

Permalink
chore(android): set location API as a default provider (michalchudzia…
Browse files Browse the repository at this point in the history
  • Loading branch information
michalchudziak authored Nov 14, 2022
1 parent 741a353 commit dfbbdff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Supports TurboModules ⚡️ and legacy React Native architecture.

Fully compatible with TypeScript.

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.
Supports modern [Play Services Location API](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient.html).


## Supported platforms
Expand Down Expand Up @@ -139,7 +139,7 @@ Supported options:

* `skipPermissionRequests` (boolean) - Defaults to `false`. If `true`, you must request permissions before using Geolocation APIs.
* `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`.
* `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.
* `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.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ public class GeolocationModule extends ReactContextBaseJavaModule {
public GeolocationModule(ReactApplicationContext reactContext) {
super(reactContext);
mConfiguration = Configuration.getDefault();
GoogleApiAvailability availability = new GoogleApiAvailability();
if (availability.isGooglePlayServicesAvailable(reactContext.getApplicationContext()) == ConnectionResult.SUCCESS) {
mLocationManager = new PlayServicesLocationManager(reactContext);
} else {
mLocationManager = new AndroidLocationManager(reactContext);
}

mLocationManager = new AndroidLocationManager(reactContext);
}

@Override
Expand All @@ -54,10 +48,14 @@ public void setConfiguration(ReadableMap config) {
}

private void onConfigurationChange(Configuration config) {
ReactApplicationContext reactContext = mLocationManager.mReactContext;
if (Objects.equals(config.locationProvider, "android") && mLocationManager instanceof PlayServicesLocationManager) {
mLocationManager = new AndroidLocationManager(mLocationManager.mReactContext);
mLocationManager = new AndroidLocationManager(reactContext);
} else if (Objects.equals(config.locationProvider, "playServices") && mLocationManager instanceof AndroidLocationManager) {
mLocationManager = new PlayServicesLocationManager(mLocationManager.mReactContext);
GoogleApiAvailability availability = new GoogleApiAvailability();
if (availability.isGooglePlayServicesAvailable(reactContext.getApplicationContext()) == ConnectionResult.SUCCESS) {
mLocationManager = new PlayServicesLocationManager(reactContext);
}
}
}

Expand Down

0 comments on commit dfbbdff

Please sign in to comment.