我现在在我的项目中使用 google direction API,我还需要两个地方之间的估计行程时间,包括路况。所以我传递出发时间:星期四 07-January-2016 时间:14:10 PM ( 1452175200 )
根据 google direction API 文档。
查看实时谷歌地图和谷歌方向 API 之间的区别,并建议我是否做错了什么。
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
两个响应必须相同或近似,但在这里我们可以看到巨大的差异。谁能推荐我?
最佳答案
时区复杂度
API 采用 UTC 时间 departure_time。
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).
错误来源
您的假设是实时 Google map 时间以 IST 为单位。
您对 2016 年 1 月 7 日下午 14:10 的实时谷歌地图响应实际上意味着洛杉矶下午 2:10,即 2016 年 1 月 7 日星期四 22:00:00 UTC(出发时间 = 1452204600)。
结果验证
2016 年 1 月 7 日下午 2:10 的实时 Google map 结果:
- 通常 28 分钟 - 1 小时 5 分钟
- 通常 35 分钟 - 1 小时
- 通常 30 分钟 - 1 小时 5 分钟
对应时间(departure_time = 1452204600)从API获取的结果:
- 最佳猜测:39 分钟
- 悲观:1 小时 1 分钟
- 乐观:28 分钟
PS:要获得与您的 API 结果相对应的实时 map 结果,请选择“出发时间”=6:00AM。
关于php - 谷歌方向 API 旅行时间与实时谷歌地图不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588473/