I thinks there are two ways to achieve this:
Firstly, if you refer the Location class in android, you can find out that it has got a method named getSpeed
. It says:
Returns the speed of the device over ground in meters/second.
If hasSpeed() is false, 0.0f is returned.
So, you may write, something like this
if (locationObj.hasSpeed()) {
float speed = locationObj.getSpeed();
// process data
} else {
// Speed information not available.
}
Secondly, you may track gps location updates, so that, you store previous location and time at which that update occurs. Now, each time a new update comes you can find the distance travelled using distanceTo
method of Location
class. So, to know the current speed, you may use the formula, distance travelled / time difference between the updates