Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google direction API travel time is different from live google map

I am using the google direction API in my project now I also need the estimated travel time between two places including traffic. So I am passing the departure time : Thursday 07-January-2016 time: 14:10 PM ( 1452175200 ) as per the google direction API documentation.

See the difference between live google map and google direction API and suggest if I am doing wrong anything.

Live google map response: (Thursday 07-January-2016 time: 14:10 PM )

https://www.google.com/maps/dir/Los+Angeles+International+Airport,+1+World+Way,+Los+Angeles,+CA+90045,+United+States/Beverly+Hills,+CA/@34.0077875,-118.4795875,12z/data=!3m1!4b1!4m17!4m16!1m5!1m1!1s0x80c2b0d213b24fb5:0x77a87b57698badf1!2m2!1d-118.40853!2d33.9415889!1m5!1m1!1s0x80c2bc04d6d147ab:0xd6c7c379fd081ed1!2m2!1d-118.4003563!2d34.0736204!2m3!6e0!7e2!8j1452175200

typically 28 min - 1 h 15 min

typically 35 min - 1 h 10 min

02:14 PM to 03:28 PM 1 h 14 min

****************************

Google direction API:

//Source address
$a = 'Los Angeles International Airport, 1 World Way, Los Angeles, CA 90045, United States'; 
//Destination address
$b = 'Beverly Wilshire, Beverly Hills (A Four Seasons Hotel), 9500 Wilshire Boulevard, Beverly Hills, CA 90212, United
        States';

//Pass source and destination address in google map API for PESSIMISTIC
$url = 'https://maps.googleapis.com/maps/api/directions/xml?origin='. urlencode($a).'&destination='. urlencode($b).'&departure_time=1452175200&mode=driving&traffic_model=pessimistic&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//output:  duration_in_traffic =  38 mins

//Pass source and destination address in google map API for OPTIMISTIC
$url = 'https://maps.googleapis.com/maps/api/directions/xml?origin='. urlencode($a).'&destination='. urlencode($b).'&departure_time=1452175200&mode=driving&traffic_model=optimistic&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//output:  duration_in_traffic = 27 mins

//Pass source and destination address in google map API for BEST_GUESS
$url = 'https://maps.googleapis.com/maps/api/directions/xml?origin='. urlencode($a).'&destination='. urlencode($b).'&departure_time=1452175200&mode=driving&traffic_model=best_guess&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//output:  duration_in_traffic = 30 mins

Both response must be same or approximate, but here we can see the huge difference. Can anyone suggest me?

like image 670
Raghbendra Nayak Avatar asked Jan 04 '16 09:01

Raghbendra Nayak


1 Answers

Timezone Complexity

The API takes departure_time in UTC.

And it seems that the live Google map takes the timezone of the origin, when 'Depart at' is chosen (and maybe of destination, when 'Arrive by' is selected).

Source of error

Your assumption was that the live Google map time is in IST.

Your live google map response for 07-January-2016 14:10 PM actually means 2:10 PM in Los Angeles, which translates to Thursday, 7 January 2016, 22:00:00 UTC (and departure_time = 1452204600).

Result verification

Live Google map results for Jan 7, 2016, 2:10 PM:

  • typically 28 min - 1 h 5 min
  • typically 35 min - 1 h
  • typically 30 min - 1 h 5 min

Results obtained from API for corresponding time (departure_time = 1452204600):

  • best_guess: 39 mins
  • pessimistic: 1 hour 1 min
  • optimistic: 28 mins

PS: To get live map results corresponding to your API results, select 'Depart at'=6:00AM.

like image 51
jatinderjit Avatar answered Oct 06 '22 17:10

jatinderjit