Google Maps Directions in current traffic with waypoints

邮差的信 提交于 2021-02-04 19:10:14

问题


I am using the google maps api to get directions with the durationInTraffic option.

var request = {
    origin: start_address,
    destination: end_address,
    waypoints: waypts,
    durationInTraffic: true,
    optimizeWaypoints: true,
    travelMode: tmode
};

directionsService.route(request, function(response, status) { ....

This is working fine with a start and end address with no waypoints, as seen below:

Directions with Time in Current Traffic

My problem is that when i add a waypoint to to route then the "time in current traffic" estimate is no longer shown.

Is this a limitation of the API (I have found no documentation supporting that)? Or a possible fix / workaround as the traffic information is very important to my app.


回答1:


I asked a similar question to the folks at Google about whether this was because I was using the stopover = true option in the waypoints and indeed it was. If you set it stopover to false, the duration in traffic should be returned.

There was small mention of this in the current documentation here

From Google:

... we can't predict how long you will stop at stopovers, making it difficult to give a proper estimation for the duration_in_traffic. By using non stopover waypoints you state that you wont stop at those waypoints, thus allowing our service to estimate the duration_in_traffic of every legs.

Also, they mentioned that if your using the Directions Matrix API, only origin/destination pairs count against your quota, so you can send multiple request without additional penalty.



来源:https://stackoverflow.com/questions/23605262/google-maps-directions-in-current-traffic-with-waypoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!