Google Directions API Transit API returns Zero_Results, manual Google Maps search

I looked at the documentation in the Google Directions API, and also looked online and did not find the answer to my puzzle. My agency developed an API to find the last possible departure between sources and destinations using transit, and there are several that return No_Result errors. However, I can return results when searching on Google Maps manually.

The Google Directions API program sends the following request:

https://maps.googleapis.com/maps/api/directions/json?units=imperial&origin=650+Memorial+Dr+chicopee+MA&destination=50+College+St+South+Hadley+MA&arrival_time=1461301200&mode=transit

which returns:

{ "available_travel_modes" : [ "DRIVING", "BICYCLING", "WALKING" ], "geocoded_waypoints" : [ { "geocoder_status" : "OK", "place_id" : "ChIJ7VtqLK7d5okR-bTUfKuHVpo", "types" : [ "street_address" ] }, { "geocoder_status" : "OK", "place_id" : "ChIJxwHLSqzb5okR1rrjYhcDvkc", "types" : [ "premise" ] } ], "routes" : [], "status" : "ZERO_RESULTS" } 

However, when I manually request Google maps, I can return the result through transit.

https://www.google.com/maps/dir/650+Memorial+Drive,+Chicopee,+MA/50+College+Street,+South+Hadley,+MA/@42.2678007,-72.7164286,11z/data= ! 3m1 4b1 4m18 4m17 1m5 1m1 1s0x89e6ddae2c6a5bed :!!!!!!!!! 0x9a5687ab7cd4b4f9 2m2 1d-72.5797548 2d42.1751992 1m5 1m1 1s0x89e6dbac4b2aac81:!!! 0xe9809aca8e8e0bdc 2m2 1d-72.5766752 2d42.2538136 2m3 6e1 7e2!!!!!! ! 8j1461200400! 3e3

I double-checked all obvious errors (for example, using "Rd" instead of "St" or entering an address that does not exist), but did not find it. I also changed the departure / arrival time in the program, no luck.

The error message looks like it indicates that MODE as TRANSIT is not an option between this origin / destination side - but then the manual interface has no problem.

Does anyone know why Google Maps may reject an API request but not a manual request? Or any resources to help figure out this problem? Thanks!!

+5
source share
2 answers

The mode ( mode=transit ) in the query string should be uppercase - try mode=transit .

+4
source

The answer “All caps” (unintentionally, but erroneously) is erroneous - the Google Maps API server does not perform the correct error checking here, and if you specify the all-caps mode parameter, it will return driving directions no matter what mode you wrote.

The real answer is that the API does not support all modes in all places, even if it is a Google Maps application. You can submit a feature request to try to push for this parity. For example, public transit in Japan: https://issuetracker.google.com/issues/35826181

Request test requests to demonstrate that the answers regarding the cards do not care what mode you specify if you do this in all the headers (be sure to add your API key):

Driving - https://maps.googleapis.com/maps/api/directions/json?departure_time=now&destination=place_id%3AChIJp4QhcgzyGGARZaBIPuJzfpg&mode=DRIVING&origin=place_id%3AChIJlyOpErWEYG101

Transit - https://maps.googleapis.com/maps/api/directions/json?departure_time=now&destination=place_id%3AChIJp4QhcgzyGGARZaBIPuJzfpg&mode=TRANSIT&origin=place_id%3AChIJlyOpErEYKGGGGG1GAP

Walking - https://maps.googleapis.com/maps/api/directions/json?departure_time=now&destination=place_id%3AChIJp4QhcgzyGGARZaBIPuJzfpg&mode=WALKING&origin=place_id%3AChIJlyOpErWEYGGGGGGGG1GAP

+1
source

Source: https://habr.com/ru/post/1247217/


All Articles