1

Uber and Ola mobile app: To calculate distance between start point & end point of the trip we cannot use Google MAP API directly as it may not give the exact route traveled by the car. How do I drop points along the travel path so that I can use them to calculate the total distance traveled?

Aryan Najafi
  • 2,438
  • 26
  • 29
vishal kokate
  • 118
  • 2
  • 12

3 Answers3

2

From whatever research I have carried out in last few days. The following method works the best in order to find out total distance traveled in the trip:

  1. Keep track of (lat,lng) along the path traveled from Start point to End Point.
  2. At the end of the trip send a call to the server with all the co-ordinates captured.
  3. Add the distance calculated from combination of lat, lng.

In order to reduce the calls to distance calculation Google map API, it is better to send calls at the end of the trip at once.

vishal kokate
  • 118
  • 2
  • 12
0

My guess is that their app is running an onLocationChanged() on the background and capturing the car speed. If you have all the speed values during the trip, you can calculate the distance traveled.

  • Can be one of the approach but this will mess up the calculation if there are multiple halts in the trip & calculation is much more complex. – vishal kokate Jul 04 '16 at 09:08
0
var rad = function(x) {


return x * Math.PI / 180;
};

var getDistance = function(p1, p2) {
  var R = 6378137; // Earth’s mean radius in meter
  var dLat = rad(p2.lat() - p1.lat());
  var dLong = rad(p2.lng() - p1.lng());
  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
    Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
    Math.sin(dLong / 2) * Math.sin(dLong / 2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  var d = R * c;
  return d; // returns the distance in meter
};

Source of above code

Community
  • 1
  • 1
Adil Malik
  • 7,633
  • 9
  • 49
  • 80
  • This is not what I am looking for. This will give an approximate distance. I want to track total distance covered by the car in the trip. – vishal kokate Jun 29 '16 at 12:51