1

I have set up a GPS tracker on a car that logs it's coordinates to a database every X minutes.

I need to know the distance this car is driving.

What is the best way to calculate this? I see google have a Distance Matrix API (https://developers.google.com/maps/documentation/distancematrix/?csw=1) but it looks like that won't handle multiple coordinates, only the start and end.

Edit: I have done some testing, and obviously since it's calculated using a straight line, the result will vary greatly depending on how often the GPS reports the position. Unfortunately, it's both data transfer/battery intensive to have it report every few seconds.

I guess there's no services that will take my coordinates, and figure out what roads the car most likely drove on? And calculate the distance of the road?

JamesB
  • 187
  • 3
  • 19
  • Every time you get an update, just calculate the distance from the last point using a straight line (using trigonometry). Then add up all your straight line distances. (The more updates you get, the more accurate it will be. Of course if the car does a U-turn between samples, it will not count some distance, but there's not much you can do about that). – halfer Mar 24 '15 at 11:47
  • If you collect your points using latitude and longitude, then [this approach will be better](http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points). – halfer Mar 24 '15 at 11:50
  • I agree that every few seconds would not be a good idea. Personally I would report every 5-10 minutes (depending on whether it is plugged into the charger) and tolerate the inaccuracy. Imagine a car travelling at 60km/hour travelling in an assumed straight line and reporting every 10 minutes (every 10km). The worst kind of inaccuracy is a U-turn after half the interval duration to get back to the same point, so this approach, even with a long interval, is inaccurate only to 5km. Depending on why you are doing this, that may be accurate enough. – halfer Mar 24 '15 at 14:10
  • (Aside: software recommendations are off-topic on Stack Overflow, so whilst you may get some ideas in the comments, the question is likely to be placed on hold). – halfer Mar 24 '15 at 14:11

0 Answers0