2

I am developing an android application which is very similar to Uber, OLA etc.

I have google maps to help the driver to navigate. Total distance is calculated from point A to B and a amount is given based on the distance travelled. The trial worked fine with just a minor 0.2 km error, which is fine!

The problem I am facing is drifting GPS and getting the speed. Drifting GPS adds unnecessary values to the distance and hence it keeps increasing. I had an idea of using :

 location.getSpeed();

from google maps API to the get the speed so that I can limit distance calculation to only when the speed is greater than 0. But the speed is always zero even if I am travelling on a vehicle, which is weird cause in reality there is actually a speed but the google maps gives me a zero speed.

Can anyone help me out in getting the speed?

Aznhar
  • 610
  • 1
  • 10
  • 30
Rahul Thyagaraj
  • 325
  • 5
  • 13
  • Check this SO question [6200461](http://stackoverflow.com/questions/6200461/calculate-speed-using-gps-in-android). Hope it can help you. – Mr.Rebot Aug 06 '16 at 05:15

1 Answers1

2

It is strange tht getSpeed() function is not working, you could maybe register your location and current time on every onLocationChange call. :

LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
         //register location and current time
    }
}

And then calculate distance between 2 location and divide it by the time between those 2 records.

Aznhar
  • 610
  • 1
  • 10
  • 30