Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Nhà phát triển ở Khu vực kinh tế Châu Âu (EEA)
Giá trị phản hồi đã bản địa hoá là một trường phản hồi bổ sung cung cấp văn bản đã bản địa hoá cho các giá trị tham số được trả về. Văn bản đã bản địa hoá được cung cấp cho thời lượng chuyến đi, khoảng cách và hệ thống đơn vị (hệ thống đo lường bằng mét hoặc hệ thống đo lường của Hoa Kỳ). Bạn yêu cầu các giá trị được bản địa hoá bằng cách sử dụng một mặt nạ trường và có thể chỉ định ngôn ngữ cũng như hệ thống đơn vị hoặc sử dụng các giá trị mà API suy luận. Để biết thông tin chi tiết, hãy xem LocalizedValues.
Ví dụ: nếu bạn chỉ định mã ngôn ngữ cho tiếng Đức (de) và đơn vị đo lường theo hệ đo lường Anh, bạn sẽ nhận được giá trị cho distanceMeters là 49889, 7, nhưng cũng nhận được văn bản đã bản địa hoá cung cấp thông tin đo lường khoảng cách bằng tiếng Đức và đơn vị đo lường theo hệ đo lường Anh, tức là "31 Meile".
Sau đây là ví dụ về những gì bạn sẽ thấy đối với các giá trị đã bản địa hoá:
Nếu bạn không chỉ định ngôn ngữ hoặc hệ thống đơn vị, API sẽ suy luận ngôn ngữ và đơn vị như sau:
Phương thức ComputeRoutes suy ra các đơn vị vị trí và khoảng cách từ điểm tham chiếu ban đầu. Vì vậy, đối với yêu cầu định tuyến ở Hoa Kỳ, API sẽ suy ra ngôn ngữ en-US và đơn vị IMPERIAL.
Phương thức ComputeRouteMatrix mặc định là ngôn ngữ "en-US" và đơn vị METRIC.
Cách yêu cầu giá trị đã bản địa hoá
Để thêm các giá trị được bản địa hoá vào phản hồi, bạn cần làm như sau:
Yêu cầu các giá trị đã bản địa hoá trong mặt nạ trường. Ví dụ:
REST
-H X-Goog-FieldMask: routes.localizedValues
RPC
const(fieldMask="routes.localizedValues")
Nếu bạn muốn các giá trị được bản địa hoá bằng một ngôn ngữ hoặc hệ thống đơn vị cụ thể, hãy chỉ định mã ngôn ngữ và hệ thống đơn vị:
[null,null,["Cập nhật lần gần đây nhất: 2025-07-22 UTC."],[[["\u003cp\u003eLocalized response values provide localized text for trip distance, duration, and unit system in Routes Preferred.\u003c/p\u003e\n"],["\u003cp\u003eYou can request localized values using a field mask and specify language and unit system or utilize the API's inferred values.\u003c/p\u003e\n"],["\u003cp\u003eIf unspecified, the API infers language and units based on the origin waypoint for \u003ccode\u003eComputeRoutes\u003c/code\u003e or defaults to 'en-US' and METRIC for \u003ccode\u003eComputeRouteMatrix\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo receive localized values, include \u003ccode\u003eroutes.localized_values\u003c/code\u003e in your field mask and optionally specify \u003ccode\u003elanguageCode\u003c/code\u003e and \u003ccode\u003eunits\u003c/code\u003e in your request.\u003c/p\u003e\n"]]],["Localized response values provide translated text for trip distance, duration, and unit system. To request them, include `routes.localized_values` in your field mask. You can specify the desired language and unit system (metric or imperial) via `languageCode` and `units`. If unspecified, the API infers them from the origin waypoint (ComputeRoutes) or defaults to 'en-US' and METRIC (ComputeRouteMatrix). The response includes localized text for distance, `duration`(with traffic model) and `staticDuration`(without traffic model).\n"],null,["# Request localized values\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\n\u003cbr /\u003e\n\nLocalized response values are an additional response field that provides\nlocalized text for returned parameter values. Localized text is provided for\ntrip duration, distance, and unit system (metric or imperial). You request\nlocalized values using a field mask, and can either specify the language and\nunit system or use the values inferred by the API. For details, see\n[LocalizedValues](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes#routelegsteplocalizedvalues).\n\nFor example, if you specify a language code for German (de) and imperial\nunits, you get a value for `distanceMeters` of 49889.7,\nbut also localized text providing that distance measurement in German and\nimperial units, so \"31 Meile.\"\n\nHere is an example of what you would see for localized values: \n\n```restructuredtext\n{ \"localized_values\":\n {\n \"distance\": { \"text\": \"31,0 Meile/n\" },\n \"duration\": { \"text\": 38 Minuten}.\n \"static_duration\": { \"text\": 36 Minuten}.\n }\n}\n```\n| Note: You get two values for the expected duration: `duration` uses the traffic model you specify, and `static_duration` does not take traffic into account. So, if your requested traffic model is `TRAFFIC_UNAWARE` these times are identical.\n\nIf you don't specify the language or unit system, the API infers the language\nand units as follows:\n\n- 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.\n- The `ComputeRouteMatrix` method defaults to 'en-US' language and METRIC units.\n\nTo request localized values\n---------------------------\n\nTo include localized values in the response, you need to do the following:\n\n1. Request localized values in your field mask. For example:\n\n **REST** \n\n ```restructuredtext\n -H X-Goog-FieldMask: routes.localizedValues\n ```\n\n **RPC** \n\n ```gdscript\n const (fieldMask = \"routes.localizedValues\")\n ```\n2. If you want the localized values in a specific language or unit system,\n specify the language code and unit system:\n\n ```console\n \"languageCode\": \"language_code\",\n \"units\": \"METRIC | IMPERIAL\",\n ```\n\n For example, this code snippet specifies the language as German (de), and\n METRIC units: \n\n ```console\n \"languageCode\": \"de\",\n \"units\": \"METRIC\",\n ```\n\n For more information, see\n [Language Support](/maps/faq#languagesupport).\n\nExample request\n---------------\n\n```curl\ncurl -X POST -d '{\n \"origin\": { \"location\": {\n \"latLng\": { \"latitude\": 37.7873146, \"longitude\": -122.4159327 } }\n },\n \"destination\": { \"location\": {\n \"latLng\": { \"latitude\": 37.7621008, \"longitude\": -122.4382503 } }\n },\n \"travelMode\": \"DRIVE\",\n \"computeAlternativeRoutes\": true,\n \"languageCode\": \"de\",\n \"units\": \"METRIC\"\n}' \\\n-H 'Content-Type: application/json' \\\n-H 'X-Goog-Api-Key: YOUR_API_KEY' \\\n-H 'X-Goog-FieldMask: routes.localizedValues' \\\n'https://routes.googleapis.com/directions/v2:computeRoutes'\n```\n\nExample response\n----------------\n\nThe response returns localized values for the `distance`, `duration`, and\n`staticDuration` fields: \n\n```json\n{\n \"localizedValues\": {\n \"distance\": {\n \"text\": \"15,5 km\"\n },\n \"duration\": {\n \"text\": \"16 Minuten\"\n },\n \"staticDuration\": {\n \"text\": \"16 Minuten\"\n }\n }\n}\n```"]]