Skip to content Skip to sidebar Skip to footer

Android Device Movement Speed

I need to calculate the movement speed on every location update. I'm using the following code for the location update. public class FlirtLocationListener implements LocationListene

Solution 1:

As @jsmith said there is a getSpeed() method in the Location.class.

publicclassLocationListenerimplementsLocationListener
    {
        @OverridepublicvoidonLocationChanged(Location location) 
        {
               floatspeed= location.getSpeed();
        }
    }

Solution 2:

But, location.getSpeed() gives null value. You must specify the setSpeed() to get location which may not be accurate. So, can calculate the speed using simple mathematical formula. Speed = distance/time.

Post a Comment for "Android Device Movement Speed"