我想从google maps api获取带有http请求的导航持续时间:https: //maps.googleapis.com/maps/api/directions/json?origin = src&destination = destination
但我得到没有交通的持续时间.我怎样才能获得流量的持续时间?
您现在duration_in_traffic无需高级帐户(只需来自开发人员控制台并启用“Google Maps Directions API”的标准 API 密钥即可获得)。在浏览器中验证
https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&departure_time=now&key=YOUR_KEY_HERE
javascript 客户端似乎使用了一个尚未返回的不同端点duration_in_traffic。
- 该请求包括一个离开时间参数。
- 该请求包含有效的 API 密钥,或有效的 Google Maps APIs Premium Plan 客户端 ID 和签名。
- 所请求路线的交通状况是可用的。
- 该请求不包括中途停留航点。
- 该请求专门针对行车路线——模式参数设置为驾驶。
在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.
Run Code Online (Sandbox Code Playgroud)
因此,您需要满足上述所有要求才能检索流量持续时间.
有关详细信息,请访问Google Directions API文档的"Leg"部分.
| 归档时间: |
|
| 查看次数: |
5721 次 |
| 最近记录: |