-2

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": [
        {}
    ]
}
  • The [example in the documentation](https://developers.google.com/maps/documentation/routes/compute_route_directions) uses this in the `X-Goog-FieldMask: routes.duration,routes.distanceMeters,...` – geocodezip Aug 20 '23 at 17:29
  • @geocodezip you are talking about `computeRoutes` api, I am talking about `computeRouteMatrix`, [here](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRouteMatrix#:~:text=For%20example%2C%20in,condition%2CdistanceMeters%2Cduration) is the documentation, sorry will update the question – questionsOnlyAccount Aug 20 '23 at 18:27
  • @geocodezip also, this is not the reason why no distance is being returned, if you send another request with the same headers but with two points that have a route between them, you can see the field returned normally – questionsOnlyAccount Aug 20 '23 at 18:28
  • @geocodezip. I updated the question with the weird responses I get for edge cases of the api – questionsOnlyAccount Aug 20 '23 at 18:37
  • @geocodezip do you know why is the api is returning empty result? – questionsOnlyAccount Aug 22 '23 at 07:48

0 Answers0