Reputation: 335
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?
Upvotes: 2
Views: 4502
Reputation: 606
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.
Upvotes: 2