Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps direction request without traffic

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?

like image 213
Lightspeed Avatar asked Nov 22 '25 07:11

Lightspeed


1 Answers

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.

like image 156
SBI Avatar answered Nov 24 '25 22:11

SBI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!