PRIORITY_LOW_POWER vs PRIORITY_HIGH_ACCURACY

5.2k views Asked by At

I have used the GoogleApiClient to get the location information. My requirement is to find the accurate location information.

In the location request I have set the priority as PRIORITY_HIGH_ACCURACY, then when I was in in door am not getting any location update when I was indoor. I need the location object needs to be returned it may be last known location.

And also I have tried PRIORITY_LOW_POWER. But it never uses the GPS to get the location information.I think using this may be bit of inaccurate.

I need the better location information when outside by using GPS and also the last known location information to be returned when I was indoor. So which priority is suitable for me?

And also always am getting the Altitude and Bearing as 0. Always am getting the fused provider. I think GoogleApiClient does not provide the provider detail which gives the location information.

Added Clarification:

I have the below implementation:

//Request for location update
LocationServices.FusedLocationApi.requestLocationUpdates(
                            mGoogleApiClient, mLocationrequest,
                            mLocationUpdatePendingIntent);


//Intent service where i receive the location information 
public LocationIntentService() {        
     super("LocationService");  
}
protected void onHandleIntent(Intent locationIntentObj) {
}


//Stop Location Update
LocationServices.FusedLocationApi.removeLocationUpdates(
                    mGoogleApiClient, mLocationUpdatePendingIntent);

In my case how can I get the last known location information from the API.

Please help me on this.

2

There are 2 answers

0
M Vignesh On

Yes I am able to get the last known location by using the following code snippet.

/**
 * Remove the user location update
 */
public void removeLocationUpdate() {
    if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
        //Remove the location update
        LocationServices.FusedLocationApi.removeLocationUpdates(
                mGoogleApiClient, mLocationUpdatePendingIntent);
        //A status message updated to the UI
        mAppUtilInstance.broadcastStatusMessage(mContext,
                Constants.STATUS_MSG_116, Constants.STATUS_CODE_116);
    }
    if (Constants.locationInformationEntity == null) {
        //Getting the last known location
        Location mLocationIntentObject = LocationServices.FusedLocationApi
                .getLastLocation(mGoogleApiClient);
        if (mLocationIntentObject != null) {
            //Storing as entity 
            mAppUtilInstance.setLocationInformationEntity(mContext,
                    mLocationIntentObject);
        }
    }
}

When i removing the location update am checking whether the api provides the location information when i was indoor. If the API fails to provides then am getting the last known location information when the location request is removed.

Hope this one helps others who are working in the fused location api.

8
Eugen Pechanec On

[...] then when I was in in door am not getting any location update when I was indoor. [...] And also always am getting the Altitude and Bearing as 0.

You have no access to GPS satellites indoor. Those values would be provided by GPS.

I suggest you use methods setInterval(...) and setFastestInterval(...). By this you are saying:

I want any location at least every interval milliseconds but if you have a good location sooner than that I am capable of processing it every fastestInterval milliseconds.

When the fused does not connect to GPS in interval milliseconds it should fall back to network provider in the background (which should in the meantime get accurate location from Wi-Fi).

You are welcome to use FusedLocationProviderApi.getLastLocation(GoogleApiClient) method before setting up recurring listening. This will return immediately but the accuracy may vary.

EDIT: If the above does not work... In my project I use fused provider in the background all the time with balanced power priority. Then I ask extra the standard GPS provider.