I have this request for google routes api (https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix)
{
"origins": [
{
"waypoint": {
"location": {
"latLng": {
"latitude": 34.84622828970363,
"longitude": 33.05384040928585
}
}
}
}
],
"destinations": [
{
"waypoint": {
"location": {
"latLng": {
"latitude": 34.84616588444302,
"longitude": 33.05378626732776
}
}
}
}
]
}
with the header:
X-Goog-FieldMask: originIndex,destinationIndex,status,condition,distanceMeters,duration
I got this response
[
{
"originIndex": 0,
"destinationIndex": 0,
"status": {},
"duration": "0s",
"condition": "ROUTE_EXISTS"
}
]
Why the response does not contain distanceMeters
field although I specified it in the header?
I tried adding the x-goog-field header to contain the fields I am interested about in the response, I expected the distance field to be returned, but it was not
Update:
After playing with the routes api for both available methods in this new api (computeRoutes and computeRouteMatrix), I found that it acts in a weird way that makes it hard to depend on it without putting alot of if-else in your code to check the returned distance. I am talking about it acting weird in cases like:
- asking for a route between 2 points on the land that are very close (few meters away), where the response of the route matrix is like:
[
{
"originIndex": 0,
"destinationIndex": 0,
"status": {},
"duration": "0s",
"condition": "ROUTE_EXISTS"
}
]
As you can see there is no distanceMeters although I included it in the headers mask. And for the same 2 points, more weirdly, this is the response of the computeRoute api (with header mask = routes.distanceMeters)
{
"routes": [
{}
]
}