1
I need to calculate the average speed (Km/h) and show this information in the Activity in "real time", as shown in the GPS Apps.
How to do such calculation and encode it on Android?
1
I need to calculate the average speed (Km/h) and show this information in the Activity in "real time", as shown in the GPS Apps.
How to do such calculation and encode it on Android?
5
http://developer.android.com/reference/android/location/Location.html#getSpeed()
Obtain the speed, if available, in metres/second from the ground. If this location does not have a speed of 0.0 is returned.
if you need to convert it to km/h:
int speed=(int) ((location.getSpeed()*3600)/1000);
0
If you really want to calculate speed on your own, go and study geodesic 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 you have travelled, the greater the error you will enter in the calculation.
There is an alternative with no work of horn better: use the method getSpeed
of the Location class ;)
Browser other questions tagged android
You are not signed in. Login or sign up in order to post.
(Initial Distance - Current Distance)/(Initial Time - Final Time)?
– Beterraba
Show, but how to expose it by Android? Need to use GPS coordinates?
– felipearon
Probably.
– Beterraba
@Beet and OP: it is not simple. If the earth were flat it would be exactly as Beet indicated. Unfortunately the earth is a spheroid, so you have to use geodesic calculus. I sincerely hope that the Android localization API already has that calculation ready.
– Oralista de Sistemas
That’s what I thought too... rs, I believe it is not a simple calculation, but I also hope that Android return me something "ready".
– felipearon
The method Location.distanceTo() already help? It returns the distance in meters between two positions considering the Earth a ellipsoid WGS84.
– Piovezan