1

I need to calculate the total distance traveled from a location to a destination.

However, it's not as simple as the distance between two points. I need to calculate the total distance along a certain path, so I'll have a few other locations that must be visited before I arrive at the destination.

Is this possible via PHP, I've done it in JS but my PHP background is not as strong...

Ricky
  • 823
  • 2
  • 14
  • 31
  • 1
    does this answer your question? http://stackoverflow.com/questions/2296087/using-php-and-google-maps-api-to-work-out-distance-between-2-post-codes-uk – devlin carnate Aug 21 '15 at 22:53
  • haversine formula is what you need. check this SO post [http://stackoverflow.com/questions/10053358/measuring-the-distance-between-two-coordinates-in-php](http://stackoverflow.com/questions/10053358/measuring-the-distance-between-two-coordinates-in-php) – mdamia Aug 21 '15 at 23:02
  • Not exactly what I wanted, but eventually lead me to my solution... I'll post it bellow. – Ricky Aug 22 '15 at 05:08

1 Answers1

0

So I ended up looking more into the issue. It seems there's no straight API that will solely calculate the distance between multiple points...

However, with a little bit of effort we are able to calculate the distance traveled using this API...

https://developers.google.com/maps/documentation/directions/intro

Essentially we want to get a route (index 0 should be fine) we then want to iterate over each of it's legs and add each legs distance.value to a total sum. The result is the distance of all destinations...

Only downside, you also get a bunch of unnecessary information as this API is meant for giving directions.

Ricky
  • 823
  • 2
  • 14
  • 31