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
You're pretty much on the right track:
1- The more reliable indicator that
computeRoutesfound no routes would the that theroutesfield is missing. I would not recommend relying on an entirely empty response, the Routes API may introduce additional fields in the future that may be present even when noroutesare returned (e.g. Directions API returnsavailable_travel_modes) sometimes).2- For
computeRouteMatrix, theconditionresponse field seems to be the reliable way to know whether a route was found or not (for each element).3- In terms of which fields in the response are nullable, IIUC all fields are nullable, at least in theory. In practice,
computeRouteMatrixresponses will probably always have at least a non-empty array of elements unless the request is rejected (invalid request values, bad/missing API key, etc.).