Search code examples
androidgeolocationlocationgoogle-play-services

LocationRequest smallest displacement and accuracy


I'm building an Android app in which I need to have a very accurate location at a very high frequency. I dove into google play services api for location, and found the LocationRequest.setSmallestDisplacement very useful to limit battery consumption.

However, as I am testing it indoor, the locations I get have an accuracy that varies a lot (sometimes 10m, sometimes 96m...), even when I set the Priority of my request as high accuracy.

My prob1em is that setSmallestDisplacement doesn't give a sh*it about the accuracy that is returned last. So if I get a location with a very low accuracy, I will still have to walk my "smallest displacement" distance to get a new one, hopefully more accuracte.

I wonder if there is a way to avoid such data (I can't use location that are not accurate enough) or if I have to skip the setSmallestDisplacement part (bad for battery consumption).

Some code for your pleasure:

mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(100); //We get a new location every 100ms or so
//mLocationRequest.setSmallestDisplacement(5);  //but only if we traveled 5m
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

Thanks.


Solution

  • The "LocationRequest.setSmallestDisplacement" doesn't matter for accuracy, it's just to avoid unnecessary updates, you can continuing using that.

    There is no method to enhance low accuracy, you just get a point with some accuracy (better or worse), if you are not interested on positions with low accuracy just skip this location and wait for a better one.

    This page could help you about accuracy and consumption, but take in mind no perfect accuracy exist, with Wi-Fi the accuracy is 100m for worse accuracy.

    Here you have the accuracy for each priority.
    https://developer.android.com/training/location/receive-location-updates.html#location-request

    Here the IO Session from Google engineers, very useful, you can get the PDF there too.
    https://developers.google.com/events/io/sessions/325337477

    Updated Links brokens

    The PDF Presentation

    The IO session

    Hope this helps :D.