How to calculate the average speed (Km/h)?

I need to calculate the average speed (Km / h) and show this information in the Activity in "real time", the same is shown in GPS Apps.

How to do such calculation and code it on Android?

 1
Author: felipearon, 2014-08-25

2 answers

Http://developer.android.com/reference/android/location/Location.html#getSpeed()

Get the speed, if available, in meters / second relative to the ground. If this location does not have a speed of 0.0 it is returned.

If you need to convert it to km / h:

int speed=(int) ((location.getSpeed()*3600)/1000);
 5
Author: MisterLimao Ml, 2014-08-25 14:43:22

If you really want to calculate the velocity on your own, go study Geodetic geometry. It's more of a math problem than a programming problem. Or you can assume that for small distances the Earth is flat. Remember that if you do this, the greater the distance traveled, the greater the error you will enter in the calculation.

Is there an alternative without horn work better: use the method getSpeed from Location Class;)

 0
Author: Garoto de Programa, 2014-08-25 14:42:08