使用 traffic_model 和 arrival_time

Using traffic_model with arrival_time

当我试图获得悲观的旅行时间以在特定时间到达目的地时,我收到错误消息: { "error_message" : "Invalid request. Missing the 'departure_time' parameter.", "routes" : [], "status" : "INVALID_REQUEST" } 我的要求是:https://maps.googleapis.com/maps/api/directions/json?units=metric&origin=Split&destination=Solin&mode=driving&language=hr&arrival_time=1518969600&traffic_model=pessimistic&key=*KEY*

当我使用 departure_time 而不是 arrival_time 或当我不使用 traffic_model(然后它默认为 "best_guess")选项时,我会得到结果还好

因为arrival time只能指定给travel mode = transit

正如 documentation 所说:

The departure time may be specified in two cases:

For requests where the travel mode is transit: You can optionally specify one of departure_time or arrival_time. If neither time is specified, the departure_time defaults to now (that is, the departure time defaults to the current time).

For requests where the travel mode is driving: You can specify the departure_time to receive a route and trip duration (response field: duration_in_traffic) that take traffic conditions into account. This option is only available if the request contains a valid API key, or a valid Google Maps APIs Premium Plan client ID and signature. The departure_time must be set to the current time or some time in the future. It cannot be in the past.

如果为其他请求提供到达时间,将被忽略。

您可以尝试自己提出您对中转方式和到达时间的要求: https://maps.googleapis.com/maps/api/directions/json?units=metric&origin=Split&destination=Solin&mode=transit&language=hr&arrival_time=1518969600&traffic_model=pessimistic&key=YOURKEY