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

1

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

How to make such a calculation and encode it on Android?

    
asked by anonymous 25.08.2014 / 16:15

2 answers

5

link

Get the speed, if available, in meters / second from 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);
    
25.08.2014 / 16:43
0

If you really want to calculate the speed on your own, go study geodesic geometry. It's more of a math problem than programming. 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 that you enter in the calculation.

There is a better alternative to corno work: use the getSpeed of the Location class;)

    
25.08.2014 / 16:42