3

I have to write a program, that tells me the shortest way between two points. The traffic shouldn't be regarded.

My Request is this.

'http://maps.googleapis.com/maps/api/directions/json?origin='.$from.'&destination='.$to.'&alternatives=true&sensor=false'

Then I take the shortest route this way

$data = json_decode(file_get_contents($url))->routes;
usort($data,create_function('$a,$b','return intval($a->legs[0]->distance->value) - intval($b->legs[0]->distance->value);'));
return floatval($data[0]->legs[0]->distance->text);

But this result depends to the actual traffic. How can I send a request, that ignores the actual traffic?

Lightspeed
  • 65
  • 1
  • 8

1 Answers1

5

Have you tried using the Distance Matrix Service?

Considering the API documentation, this should be what you're looking for:

Google's Distance Matrix service computes travel distance and journey duration between multiple origins and destinations using a given mode of travel.

This service does not return detailed route information.

Traffic situations should be ignored using this service.

Community
  • 1
  • 1
SBI
  • 2,322
  • 1
  • 17
  • 17