Request localized values

Localized response values are an additional response field that provides localized text for returned parameter values. Localized text is provided for trip duration, distance, and unit system (metric or imperial). You request localized values using a field mask, and can either specify the language and unit system or use the values inferred by the API. For details, see LocalizedValues.

For example, if you specify a language code for German (de) and imperial units, you get a value for distanceMeters of 49889.7, but also localized text providing that distance measurement in German and imperial units, so "31 Meile."

Here is an example of what you would see for localized values:

{ "localized_values":
  {
    "distance": { "text": "31,0 Meile/n" },
    "duration": { "text": 38 Minuten}.
    "static_duration": { "text": 36 Minuten}.
  }
}

If you don't specify the language or unit system, the API infers the language and units as follows:

  • The ComputeRoutes method infers the location and distance units from the origin waypoint. So for a routing request in the US, the API infers en-US language and IMPERIAL units.
  • The ComputeRouteMatrix method defaults to 'en-US' language and METRIC units.

To request localized values

To include localized values in the response, you need to do the following:

  1. Request localized values in your field mask. For example:

    REST

    -H X-Goog-FieldMask: routes.localized_values

    RPC

    const (fieldMask = "routes.localized_values")
  2. If you want the localized values in a specific language or unit system, specify the language code and unit system:

    "languageCode": "language_code",
    "units": "METRIC | IMPERIAL",

    For more information, see Language Support.

    For example, this code snippet specifies the language as German (de), and METRIC units:

    "languageCode": "de",
    "units": "METRIC",

Example request

curl -X POST -d '{
  "origin": { "location": {
    "latLng": { "latitude": 37.7873146, "longitude": -122.4159327 } }
  },
  "destination": { "location": {
    "latLng": { "latitude": 37.7621008, "longitude": -122.4382503 } }
  },
  "travelMode": "DRIVE",
  "computeAlternativeRoutes": true,
  "languageCode": "de",
  "units": "METRIC"
}' \
-H 'Content-Type: application/json' \
-H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H 'X-Goog-FieldMask: routes.localized_values' \
'https://routes.googleapis.com/directions/v2:computeRoutes'

Example response

The response returns localized values for the distance, duration, and staticDuration fields:

{
    "localizedValues": {
        "distance": {
            "text": "15,5 km"
         },
        "duration": {
            "text": "16 Minuten"
        },
        "staticDuration": {
            "text": "16 Minuten"
        }
    }
}