0
votes

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

1 Answers

1
votes

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