Google 方向矩阵 API 有问题

Probleme with Google Direction Matrix API

我试图从 API.

中找到 duration_in_traffic

当我像这样使用 Distance Matrix Service 对象时 :

service.getDistanceMatrix(
{
    origins         : i === 0 ? [origin] : [destination],
    destinations    : i === 0 ? [destination] : [origin],
    travelMode      : google.maps.TravelMode.DRIVING,
    drivingOptions  : {
        departureTime   : departureTime[i],
        trafficModel    : google.maps.TrafficModel.PESSIMISTIC
    }
}, callbackCar);

结果不包含 duration_in_traffic 字段。


当我将 GET API 服务与 JSONP 一起使用时,控制台包含一个 意外标记:错误 ...

getDelay: function() {
    return $resource('https://maps.googleapis.com/maps/api/distancematrix/json', {
        key: ACCESS.ggAPI,
        origins: "@origins",
        destinations: "@destinations",
        language: "fr-FR",
        mode: "@mode",
        transit_mode: "@transitMode",
        traffic_model: "@traffic_model"
    }, {                        
        get: {
            method: 'JSONP'
        }
    });
}

当我尝试使用 GET 而不是 JSONP 时,我遇到了 CORS 问题...

当我尝试将 angular 服务构建的 uri 放入另一个 window 时,我可以找到正确的结果:

{
   "destination_addresses" : [ "93200 Saint-Denis, France" ],
   "origin_addresses" : [ "95500 Gonesse, France" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "16,7 km",
                  "value" : 16746
               },
               "duration" : {
                  "text" : "19 minutes",
                  "value" : 1133
               },
               **"duration_in_traffic" : {
                  "text" : "23 minutes",
                  "value" : 1391
               },**
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

我能做什么?

如果没有高级计划,您将无法获得 duration_in_traffic 属性。

The total duration of this leg, taking into account the traffic conditions indicated by the trafficModel property. This property may be undefined as the duration may be unknown. Only available to Premium Plan customers when drivingOptions is defined when making the request.

Source