javascriptgoogle-mapsgoogle-directions-api

Google maps API is returning ZERO_RESULTS for a directions request via API, but works on Google maps


Problematic call in question is:

https://maps.googleapis.com/maps/api/directions/json?origin=35.73455050,-95.31531510&destination=29.67404860,-95.54087240&waypoints=29.92853940,-95.29782860|29.61621200,-95.31759150&mode=driving&key=[API_KEY]

Which returns:

{
  "available_travel_modes": [
    "DRIVING",
    "WALKING",
    "BICYCLING"
],
"geocoded_waypoints": [
   {},
   {},
   {},
   {}
 ],
  "routes" : [],
  "status" : "ZERO_RESULTS"
}

I have read in this answer that if you use via: on your waypoints, some maneuvers like a U-turn is not allowed. When you display my trip on the Google maps, there is one U-turn and if I slightly change the waypoint in order to remove that U-turn then I get valid results from the API call. I'm confused as to why my request is failing due to a U-turn even if I'm not using via: for waypoints.

My question would be how to be able to support routes that may include U-turns?

Note: Thousands of other calls are working as they should, no rate limiting is in place, this is an exception.


Solution

  • The same request also cannot find a route on Google Maps.

    The problematic location is 29.92853940,-95.29782860 and the problem is that the closest road segment to that location (29.928413,-95.297976) is a one-way segment.

    The closest road segment is often not the desired one for routing, which is why the best approach to reliably obtain the best available directions from the Directions API (and Routes API, and even Google Maps using Maps URLs) is to specify waypoints as Place ID, e.g.

    https://maps.googleapis.com/maps/api/directions/json?origin=35.73455050,-95.31531510&destination=29.67404860,-95.54087240&waypoints=place_id:ChIJrRBC-DqxQIYRG8Pa87ipZ3M|29.61621200,-95.31759150&mode=driving