简体   繁体   English

Google Directions Javascript API不会返回Duration_In_Traffic

[英]Google Directions Javascript API Doesn't Return Duration_In_Traffic

I'm trying to use google direction JavaScript API to estimate a trip duration in traffic but for some way it's not returned as a part of the JSON array anyway here's how I call the service 我正在尝试使用谷歌方向JavaScript API来估计流量的行程持续时间但是从某种程度上它不作为JSON数组的一部分返回,无论如何这里是我如何调用服务

        ser.route(
        {
            'origin': Markers[0].position,
            'destination': Markers[Markers.length - 1].position,
            'waypoints': wayPoints,
            'travelMode': google.maps.DirectionsTravelMode.DRIVING,
            'provideRouteAlternatives': true,
            drivingOptions: {
                departureTime: new Date (Date.Now),
                trafficModel: google.maps.TrafficModel.BEST_GUESS
            }

but when I try to get the duration in traffic this way 但是当我试图以这种方式获得交通的持续时间

var minutes = element.legs[0].duration_in_traffic.value;

firebug returns 萤火虫回归

element.legs[0].duration_in_traffic is undefined element.legs [0] .duration_in_traffic未定义

I'm pretty sure the region is traffic supported but I can't know why the duration in traffic isn't returned 我很确定该地区是受流量支持的,但我不知道为什么不返回流量的持续时间

This problem appears to be limited to the javascript client. 此问题似乎仅限于javascript客户端。 You can make a GET request to the Directions API from your browser as described in my answer here . 您可以在浏览器中向Directions API发出GET请求,如我在此处的回答中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM