Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fused Location Provider - onLocationChanged stops getting called

In our app we used the Fused Location Provider (FLP) to track location. We've noticed that occasionally the app can get into a state where the location callback stops getting called. The app in question is used primarily on two tablets (a nexus 7 and LG G-pad 8.3). We have seen the issue occur on both devices. In general resetting the device seems to alleviate the issue. We believe we follow most of the best practices for using the FLP. But just in case we put together this sample code which illustrates how we use the FLP.

Get a google api client and call connect:

m_googleApiClient = builder
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
m_googleApiClient.connect()

Once connected we start listening for location callbacks:

@Override
public void onConnected(Bundle bundle) {
    m_fusedLocationProviderApi.requestLocationUpdates(m_googleApiClient, m_locationRequest, this);
}

The location request looks like this:

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);

We then implement the callback like so:

    @Override
public void onLocationChanged(Location location) {
   // set location member var and record timestamp.
}

When the issues occurs we don't appear to get any error callbacks. We've tried also calling reset() on the google api client when we detect we haven't received a GPS in a long time. We also monitor location availability using a timer every 2 seconds (using getLocationAvailability). Typically we find that having the user reset their device (power on, power off) fixes the issue.

Our questions are:

  1. Has anyone else noticed this issue with FLP?
  2. Is there more we can do to fix the issue short of having the user reset? Would remove adding location updates help?
  3. Is there more information we can/should collect to diagnose the issue?
like image 618
noahd Avatar asked May 23 '16 15:05

noahd


People also ask

How accurate is fused location provider?

The accuracy values are typically more than 10 meters, while a third party GPS app (such as GPS test) typically reaches better accuracy if I wait long enough.

What does fused location mean on my phone?

The fused location provider is a location API in Google Play services that intelligently combines different signals to provide the location information that your app needs.

How do I disable fused location provider?

Download the app Disable Service. In the app select the System tab search for the service named Fused Location and disable it. Also search for the service group Google Play Services. Inside it there will be another Fused Location service.

How does fused location work?

The fused location provider is one of the location APIs in Google Play services. It manages the underlying location technology and provides a simple API so that you can specify requirements at a high level, like high accuracy or low power. It also optimizes the device's use of battery power.


1 Answers

I have worked with FusedLocationProvider extensively on a broad spectrum of devices, both low-end & high-end and have seen similar issues where GPS data had bad patches in between. Because of this, I made a few changes catering to these issues related to reliability & robustness (as listed below) and haven't seen these issues after that.

In my experience, the possible solutions to such issues are:

  1. Updating Play services: I was using Android Play services versions in the range of 7.x - 8.x when I had these issues.

    Sol: In the recent past, updating to 10.x versions of play services have helped in resolving the issues. We've not seen these issues post the update, so this could definitely be one of the reasons in your case as well.

  2. Making Android Service more reliable & robust: This is one of the major reasons we saw blackouts in GPS data and while restarting the device or initializing the setup again, we generally restart the service. And hence, the service starting up back again might resume location updates to normal.

    Sol: I use a Foreground Service instead of background service and this is by far the most reliable solution here but this comes with a sticky UI notification for the user. If not for this, then keeping a health check (running or killed) for the background service can be a good option as well.

  3. Reconnecting GoogleAPIClient on connection suspension/error I have seen situations where the GoogleAPIClient connection is suspended or returns an error because of bad network conditions or other reasons. Although I was not able to validate a direct impact of this on the loss of location data, this could very well be a reason in this case. To support this, the resetting of location updates will fail in case this GoogleAPIClient connection issue happens and this is what has been observed by you as well.

    Sol: A simple reconnection of GoogleAPIClient on suspension or error can resolve this.

Apart from these, there is one more reason which could be responsible for this issue:

Device GPS fix lost: There are times when the device loses its GPS fix resulting in absence of GPS data till the time it can get back the GPS fix. There is absolutely no way of determining whether the location was lost because of a GPS fix. Resetting device's location settings have an impact of the device attempting for a GPS fix, which could possibly be the reason here as well.

DISCLAIMER: I am an Android Developer @ HyperTrack and we're developing a location stack for developers who are building location features in their apps and these are the kind of problems we have been solving. It would be great for you to test out similar scenarios using our SDKs and in case you still see the issue we would be happy to help you in getting to its root cause and fixing the issue.

like image 86
Piyush Gupta Avatar answered Oct 04 '22 13:10

Piyush Gupta