javaandroidlocationfusedlocationproviderapi

Fused location provider - Location.getSpeed() is very low


In my app I want to track the distance traveled.
I wanted to check whether the user is moving or not.
I tried to look at the speed values, but location.getSpeed() is always a lot lower than the real speed.

fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

locationRequest = LocationRequest.create();
locationRequest.setInterval(1000);
locationRequest.setSmallestDisplacement(0);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setWaitForAccurateLocation(true);

locationCallback = new LocationCallback()
{
   @Override
   public void onLocationResult(@NonNull LocationResult locationResult)
   {
      for (Location location : locationResult.getLocations())
      {
         //OTHER CODE
         //...

         System.out.println(location.getSpeed());

         //OTHER CODE
         //...
      }
   }
};

fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper());

The values I get don't make any sense.
Of course, when I stand still I get really small values.
But when I walk I get values around 1.
And when I'm in a car I get values around 10-15 even though I'm actually going cca 50km/h.

Am I doing something wrong, or is this normal?


Solution

  • Android Location reports speed in m/sec. 15 m/sec = 54 kph.