Pudding
Pudding

Reputation: 13

Google Directions API Travel Mode TRANSIT not working for street_address

Apologies if I'm writing obvious question. Though I cannot find document anywhere online so I have decided to ask here.

Is it the case that transit mode in Goolge Directions API is only valid if origin and destination are point of interest?

If either or both address is type street_address, I am not able to receive response containing travel_mode=TRANSIT.

What I want to achieve from the API is a result like Google Map, where it outputs optimistic route between the origin and destination; consisting waypoint(s) of public transport in the middle of the trip.

E.g. Point of Interest to Point of Interest returns fine https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=Chatswood%20station&mode=transit&transit_mode=rail&key=[key]

E.g. Point of Interest to street_address returns ZERO_RESULTS https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=441%20Victoria%20Avenue&mode=transit&key=[key]

E.g. Inserting "Wynyard Station" as origin and "441 Victoria Avenue" as destination in Google Map returns route including both transit and walk to the destination.

Upvotes: 0

Views: 1814

Answers (1)

xomena
xomena

Reputation: 32198

The issue with your request is that you are using incomplete address string '441 Victoria Avenue'. This is really ambiguous query. If you check it in Geocoder tool, you will see that this string is resolved to '441 Victoria Ave, Forrest City, AR 72335, USA'

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D441%2520Victoria%2520Avenue

So, you try to find a transit (train) directions between one place in Australia and another one in the USA.

enter image description here

ZERO_RESULTS is expected in this case. You should specify a more precise address string or use autocomplete to search transit directions using place IDs.

https://developers.google.com/maps/faq#geocoder_queryformat

https://developers.google.com/maps/documentation/geocoding/best-practices

For example, using '441 Victoria Avenue, Sydney' I can get transit directions

https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=441%20Victoria%20Avenue%2C%20Sydney&mode=transit&alternatives=true&transit_mode=train&key=YOUR_API_KEY

You can check this in Directions calculator tool:

https://directionsdebug.firebaseapp.com/?origin=Wynyard%20station&destination=441%20Victoria%20Avenue%2C%20Sydney&mode=transit&alternatives=true&transit_mode=train

Hope it helps!

Upvotes: 0

Related Questions