1
根據谷歌API文檔,所有流量模型應該有不同的值,但我得到了BEST_GUESS,PESSIMISTIC,OPTIMISTIC的相同值。Google方向API爲TrafficModel返回不正確的值
我使用下面的代碼
//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=1451491810&travelMode=google.maps.TravelMode.DRIVING&drivingOptions=trafficModel:google.maps.TrafficModel.PESSIMISTIC&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//output: duration_in_traffic = 50 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=1451491810&travelMode=google.maps.TravelMode.DRIVING&drivingOptions=trafficModel:google.maps.TrafficModel.OPTIMISTIC&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//output: duration_in_traffic = 50 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=1451491810&travelMode=google.maps.TravelMode.DRIVING&drivingOptions=trafficModel:google.maps.TrafficModel.BEST_GUESS&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//output: duration_in_traffic = 50 mins
更新:
我使用
// DEPARTURE_TIME = 04一月-2016 // 1451898000
$url = 'https://maps.googleapis.com/maps/api/directions/xml?origin='. urlencode($a).'&destination='. urlencode($b).'&departure_time=1451898000&mode=driving&traffic_model=pessimistic&key=AIzaSyC7h7m5bRs-BZwk0XTXEQTB74dZujeLzZs';
//Output
pessimistic==>>
duration_in_traffic => 31 mins
optimistic==>
duration_in_traffic => 25 mins
best_guess==>
duration_in_traffic => 25 mins
Above responses are not correct as per the live google map
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.4878535,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!8j1451898000
我究竟做錯了什麼?
見我更新其仍然沒有正確響應。 –
我們可以在google API中調用悲觀,樂觀和best_guess,並且可以在同一個調用中返回悲觀,樂觀和best_guess的響應嗎? –
afaik目前不可能 –