Request localized values

European Economic Area (EEA) developers

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."

To request localized values, take the following steps:

  1. Add the localizedValues field to the fields property of the ComputeRoutesRequest.
  2. Optionally, specify the language and unit system using the languageCode and units properties of the ComputeRoutesRequest.

Here is an example of requesting localized values:

const requestWithLocalizedValues = {
  origin: 'San Diego, CA',
  destination: 'Ensenada, MX',
  travelMode: 'DRIVING',
  language: 'es',
  units: google.maps.UnitSystem.METRIC,
  fields: ['path', 'localizedValues', 'distanceMeters', 'durationMillis'],
};
  

If you don't specify the language or unit system, 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.

To read localized values use route.localizedValues. For example:

const localizedValues = route.localizedValues;
const distance = localizedValues.distanceMeters;
const duration = localizedValues.duration;
const durationStatic = localizedValues.staticDuration;