方向 Api 参数

Directions Api Params

我想使用 google 地图方向 API 并绘制悲观的交通折线。 I looked at this URL.

https://maps.googleapis.com/maps/api/directions/json?origin=41.0050506,29.0680688&destination=41.011522,29.983513&sensor=false&trafficModel=pessimistic

我在上面为悲观流量创建了 API。但是best_guide和乐观没有区别。我不知道,URL 有问题吗?

{
  origin: 'Chicago, IL',
  destination: 'Los Angeles, CA',

  provideRouteAlternatives: false,
  drivingOptions: {
    departureTime: new Date(/* now, or future date */),
    trafficModel: 'pessimistic'
  }
}

我想 trafficmodel 参数必须在 drivingOptions 中。谁能帮我像上面这样创建 url .

感谢任何建议。

以下来自文档,Google 将使用它可用的数据,如果 Google 没有足够的数据用于该特定路线,它将 return 估计 ,所以这些是 估计

另请注意:

  • 您使用的经纬度距离不到 2 公里,尝试更大距离的路线,比如 25 公里
  • 您应该尝试另一条您知道流量更多的路线,您可能会得到不同的结果
  • bestguess (default) indicates that the returned duration_in_traffic should be the best estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer the departureTime is to now..
  • pessimistic indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, though occasional days with particularly bad traffic conditions may exceed this value.
  • optimistic indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, though occasional days with particularly good traffic conditions may be faster than this value.