Why Getspeed() Always Return 0 on Android

why getSpeed() always return 0 on android

location.getSpeed() only returns what was set with location.setSpeed(). This is a value that you can set for a location object.

To calculate the speed using GPS, you'll have to do a little math:

Speed = distance / time

So you would need to do:

(currentGPSPoint - lastGPSPoint) / (time between GPS points)

All converted to ft/sec, or however you want to show the speed. This is how I did it when I made a runner app.

More specifically, you'll need to calculate for absolute distances:

(sqrt((currentGPSPointX - lastGPSPointX)^2) + (currentGPSPointY - lastGPSPointY)^2)) / (time between GPS points)

It might help to make a new TrackPoint class or something, which keeps the GPS location and time it was taken inside.

Why does location.getSpeed() always return 0

Simply getSpeed() method only returns the speed if it is available,

If this location does not have a speed then 0.0 is returned.

If you are sure you have proper speed to be shown and has to be returned something surely then consider this codes, And try making your's same as that one.

Android LocationServices getLastLocation returns speed as 0

I'm not sure if this is what you're looking for:
https://developer.android.com/reference/android/location/Location.html#getSpeed()

But it's "normal" for getSpeed to return 0.0 to you as a default because your location does not have speed (as showed in the documentation).



Related Topics



Leave a reply



Submit