-2

I am trying the new google routes api, I tried 2 edge cases:

  • origin and destination are 2 points in the sea
  • origin and destination are 2 points in the land but are very close (<10 meters)

In first case, this is the request for computeRoutes:

{
    "origin": {
        "location": {
            "latLng": {
                "latitude": 33.29970432790808,
                "longitude": 35.070910203529856
            }
        }
    },
    "destination": {
        "location": {
            "latLng": {
                "latitude": 33.299996850855344,
                "longitude": 35.070292786688945
            }
        }
    },
    "travelMode": "DRIVE",
    "computeAlternativeRoutes": false,
    "languageCode": "en-US",
    "units": "IMPERIAL"
}

and this is the request for computeRouteMatrix:

{
    "origins": [
        {
            "waypoint": {
                "location": {
                    "latLng": {
                        "latitude": 33.29970432790808,
                        "longitude": 35.070910203529856
                    }
                }
            }
        }
    ],
    "destinations": [
        {
            "waypoint": {
                "location": {
                    "latLng": {
                      "latitude": 33.29970432790808,
                      "longitude": 35.070910203529856
                    }
                }
            }
        }
    ]
}

The responses are respectively:

{}

and

[
    {
        "originIndex": 0,
        "destinationIndex": 0,
        "status": {},
        "condition": "ROUTE_NOT_FOUND"
    }
]

As you can see, the computeRoutes returns no useful information in this case, just an empty json map, opposed to the computeRouteMatrix which returns for each origin/dest pair a condition flag indicating that no route was found.

1- Can I reliably depend on empty response for computeRoutes to know that no route was found? I can't find this case in the docs.

2- Same question for computeRouteMatrix, I want to know if this(the condition param in the response) is a reliable way to know whether no route was found at all

3- How do I know which fields in the response to these 2 calls are nullable or not? I want to create an interface for this api in dart, which has sound null safety, so I need to know when a variable can be nullable in the response. I could find the required params of the request in the docs, but the docs don't mention anything about which params in the response (for both apis) are nullable.

Note: In the above requests I am using the mask "*" to return all possible response data

HHH
  • 124
  • 1
  • 1
  • 10

1 Answers1

-1

When using the Google Routes API, you can determine if the API has found no routes by examining the response that you receive after making a request. The response will typically be in JSON format and will contain information about the routes, if any were found, or an indication that no routes were found. Here's how you can check for this: Check the "status" Field: The JSON response will include a "status" field which indicates the overall result of the request. If the status is "ZERO_RESULTS," it means that the API was unable to find any routes based on the provided parameters. Check the "routes" Array: In the JSON response, there is an array called "routes" which contains the possible routes that the API has found. If this array is empty, it's another indication that no routes were found. Evaluate the "geocoded_waypoints" Array: The "geocoded_waypoints" array provides information about the waypoints in your request. If this array is empty, it could indicate that the provided starting or ending points are not valid, which could lead to no routes being found. Remember that the exact structure of the JSON response and the status codes might change over time due to updates in the API. Make sure to refer to the official Google Routes API documentation for the most up-to-date information on how to interpret the response and handle cases where no routes are found.

  • I am already examining the response as you suggest, but as yoiu see the response in first case is an empty json ```{}``` – HHH Aug 19 '23 at 08:04