google-mapsmatrixgoogle-apidistance

How do I interpret the Google Distance Matrix API response value?


{
    "destination_addresses": [
        "New York, NY, USA"
    ],
    "origin_addresses": [
        "Washington, DC, USA"
    ],
    "rows": [
        {
            "elements": [
                {
                    "distance": {
                        "text": "225 mi",
                        "value": 361711
                    },
                    "duration": {
                        "text": "3 hours 53 mins",
                        "value": 13965
                    },
                    "status": "OK"
                }
            ]
        }
    ],
    "status": "OK"
}

I got this response from the Google Distance Matrix API. We have text and value responses on the distance and duration, how do I interpret that? What is it's unit? Thank you!

I thought the value should be the same as that of the text just not without the unit, but it's entirely different.


Solution

  • According to the documentation, the the unit for the value of distance is meters. To quote the documentation:

    The total distance of this route, expressed in meters (value) and as text. The textual value uses the unit system specified with the unit parameter of the original request, or the origin's region.

    While the unit for the value of duration is seconds. To quote the documentation:

    The length of time it takes to travel this route, expressed in seconds (the value field) and as text. The textual representation is localized according to the query's language parameter.

    The unit for text for both distance and duration is what ever you asked for in the request or localized based on the region of the world that the request is sent from or the language parameter in the query.