My Directions API request is Invalid, but Why?

百般思念 提交于 2020-01-03 05:52:08

问题


http://maps.googleapis.com/maps/api/directions/json?origin=Central+Hong+Kong&destination=Sai+Kung&sensor=false&mode=transit

The request works fine without the mode=transit parameter, but the results only include driving directions. With the last parameter added, I get this:

"status" : "INVALID_REQUEST"

What can I do to make this work? There are definitively transit options available, they are listed in Google Maps.


回答1:


INVALID_REQUEST indicates that the provided request was invalid. Common causes of this status include an invalid parameter or parameter value.

If you set the mode to "transit" you must also specify either a departure_time or an arrival_time.

From the documentation

mode (defaults to driving) — Specifies the mode of transport to use when calculating directions. Valid values are specified in Travel Modes. If you set the mode to "transit" you must also specify either a departure_time or an arrival_time.

If "departure_time" is added to the request in your question, it returns a result:

http://maps.googleapis.com/maps/api/directions/json?origin=Central+Hong+Kong&destination=Sai+Kung&sensor=false&mode=transit&departure_time=12



来源:https://stackoverflow.com/questions/17836096/my-directions-api-request-is-invalid-but-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!