michalchudziak/react-native-geolocation

Default to PlayServicesLocationManager in case of 'auto'

ifarhanpatel opened this issue · 0 comments

In the following code block, in the case of auto we default to AndroidLocationProvider instead of Playservices. We have encountered instances where AndroidLocationProvider does not return any location(even when google maps can accurately can). Since FusedLocationProvider is the latest API, we can default to PlayServices if it is available on the device.

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

A newer Code block would look something like:

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