I'm testing the accuracy of the FusedLocationProviderClient's location updates with different priorities. In the application I am first getting 15 updates with PRIORITY_HIGH_ACCURACY
, then canceling the request, changing the priority to PRIORTIY_LOW_POWER
and requesting again. I have also tried changing to ACCURACY_BALANCED_POWER_ACCURACY
and in both cases PRIORITY_HIGH_ACCURACY
has the worst performance in terms of accuracy - every single time I run my app.
Another thing I've noticed is that in the first 15 updates, the accuracy is changing quite often, while the last 15 pretty much give the same accuracy all the way. Any idea why this is happening? Here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtBatteryLevel = (TextView) findViewById(R.id.batteryLevel);
txtAccuracy = (TextView) findViewById(R.id.accuracy);
mFusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);
mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(0);
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult){
onLocationChanged(locationResult.getLastLocation());
}
};
requestLocationUpdates();
}
public void requestLocationUpdates() {
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
}
public void onLocationChanged(Location location){
int batteryLevel = Integer.valueOf(txtBatteryLevel.getText().toString());
if(batteryLevel>0) {
if (mLocationRequest.getPriority() == LocationRequest.PRIORITY_HIGH_ACCURACY) {
if (batteryLevel <= 15) {
mFusedLocationClient.removeLocationUpdates(mLocationCallback);
mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
mLocationRequest.setInterval(0);
requestLocationUpdates();
return;
}
}
txtAccuracy.setText(String.valueOf(location.getAccuracy()));
batteryLevel--;
txtBatteryLevel.setText(String.valueOf(batteryLevel));
}
}