yayaa / LocationManager

Simplify getting user's location for Android
807 stars 187 forks source link

SettingsApi doesn't turn on GPS #19

Closed miladrasooli closed 7 years ago

miladrasooli commented 7 years ago

Hi, at first let me thank you for your great job making this painless and simple library, The issue I am having with your lib is that when the GPS is off it doesn't turn it on using SettingsApi, It only enables low battery mode or something like that. In the SettingsApi dialog it mentions only WiFi and Cellular data. Thanks.

yayaa commented 7 years ago

In GPServicesLocationProvider settingsApi is created as shown below

LocationSettingsRequest settingsRequest = new LocationSettingsRequest.Builder()
                .addLocationRequest(configuration.getLocationRequest())
                .build();

        PendingResult<LocationSettingsResult> settingsResult = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, settingsRequest);
        settingsResult.setResultCallback(this);

So you can change the locationRequest as your requirements via LocationConfiguration, and that should change the way of SettingsApi configured.

And for default value of locationRequest is set in LocationConfiguration as shown below.

private void generateDefaultLocationRequest() {
        this.locationRequest = LocationRequest.create();
        locationRequest.setPriority(Default.LOCATION_PRIORITY);
        locationRequest.setInterval(Default.LOCATION_INTERVAL);
        locationRequest.setFastestInterval(Default.LOCATION_FASTEST_INTERVAL);
    }