简体   繁体   English

如何通过谷歌地图api的流量获得导航持续时间?

[英]How to get navigation duration with traffic from google maps api?

I want to get the navigation duration from google maps api with http request: https://maps.googleapis.com/maps/api/directions/json?origin=src&destination=destination 我想从google maps api获取带有http请求的导航持续时间: https//maps.googleapis.com/maps/api/directions/json?origin = src& destination / destination

but i get the duration without traffic. 但我得到没有交通的持续时间。 how can i get the duration with traffic? 我怎样才能获得流量的持续时间?

From the Google Directions API, it states that: 在Google Directions API中,它声明:

duration_in_traffic indicates the total duration of this leg, taking into account current traffic conditions. The duration in traffic will only be returned if all of the following are true:

1.The directions request includes a departure_time parameter set to a value within a few minutes of the current time.
2.The request includes a valid Google Maps API for Work client and signature parameter.
3.Traffic conditions are available for the requested route.
4.The directions request does not include stopover waypoints.

So you need to meet all the above requirements in order to retrieve duration with traffic. 因此,您需要满足上述所有要求才能检索流量持续时间。

For more information, you can visit the Leg section of the Google Directions API documentation. 有关详细信息,请访问Google Directions API文档的“Leg”部分

You are now able to get duration_in_traffic without a premium account (just a standard API key from the developer console with the "Google Maps Directions API" enabled). 您现在可以在没有高级帐户的情况下获取duration_in_traffic (只需使用启用了“Google Maps Directions API” 的开发人员控制台中的标准API密钥)。 Verify in your browser with 在浏览器中验证

https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&departure_time=now&key=YOUR_KEY_HERE

It appears that the javascript client uses a different endpoint that does not yet return duration_in_traffic . 似乎javascript客户端使用了尚未返回duration_in_traffic的不同端点。

The request must meet the following conditions, as updated in the docs : 该请求必须满足以下条件,如文档中所更新:

  • The request includes a departure_time parameter. 该请求包括departure_time参数。
  • The request includes a valid API key, or a valid Google Maps APIs Premium Plan client ID and signature. 该请求包含有效的API密钥或有效的Google Maps API Premium Plan客户端ID和签名。
  • Traffic conditions are available for the requested route. 交通条件可用于所请求的路线。
  • The request does not include stopover waypoints. 该请求不包括中途停留点。
  • The request is specifically for driving directions— the mode parameter is set to driving. 该请求专门用于驾驶方向 - 模式参数设置为驾驶。

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

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