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)
Các điểm tham chiếu trung gian là những vị trí nằm giữa điểm khởi hành và điểm đến mà bạn muốn tuyến đường đi qua. Điểm tham chiếu trung gian có thể là một điểm dừng hoặc bạn có thể chỉ định điểm này là một vị trí để đi qua. Để biết ví dụ về một điểm đánh dấu cho một điểm dừng, hãy xem phần Đặt một điểm dừng dọc theo tuyến đường. Để biết ví dụ về một điểm tham chiếu để truyền qua, hãy xem phần Đặt điểm để truyền qua cho một tuyến đường.
Sử dụng thuộc tính mảng intermediates của phương thức computeRoutes (REST) hoặc phương thức ComputeRoutes (gRPC) để xác định tối đa 25 điểm tham chiếu trung gian.
Đối với mỗi điểm tham chiếu trung gian trong yêu cầu, đối tượng Tuyến đường (REST) hoặc đối tượng Tuyến đường (gRPC) trong phản hồi sẽ thêm một mục vào mảng legs để cung cấp thông tin chi tiết cho chặng đường đó.
Mỗi chặng của một tuyến đường được biểu thị bằng một đối tượng RouteLeg (REST) hoặc RouteLeg (gRPC).
Kiểm soát những trường RouteLeg cần trả về bằng cách sử dụng mặt nạ trường phản hồi.
Ví dụ – Đặt điểm tham chiếu trung gian
Ví dụ sau đây sử dụng thuộc tính mảng intermediates để thêm một điểm tham chiếu trung gian duy nhất vào nội dung yêu cầu POST của một tuyến đường.
Ví dụ này sử dụng một mặt nạ trường phản hồi trong tiêu đề X-Goog-FieldMask để chỉ định trả về các trường sau trong phản hồi:
routes.duration
routes.distanceMeters
routes.legs tương ứng với toàn bộ đối tượng RouteLeg.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-22 UTC."],[[["\u003cp\u003eIntermediate waypoints allow you to specify locations between the origin and destination for a route to pass through or stop at.\u003c/p\u003e\n"],["\u003cp\u003eYou can define up to 25 intermediate waypoints using the \u003ccode\u003eintermediates\u003c/code\u003e property when computing routes, but requests with 11 or more are billed at a higher rate.\u003c/p\u003e\n"],["\u003cp\u003eThe response provides route details including legs, with each leg representing a segment of the journey between waypoints.\u003c/p\u003e\n"],["\u003cp\u003eEach leg within the route is further broken down into steps, providing detailed information about each segment of the journey.\u003c/p\u003e\n"]]],["Intermediate waypoints, placed between the origin and destination, guide the route. Use the `intermediates` array in the `computeRoutes` method to define up to 25 waypoints, with options for stops or pass-throughs. Each waypoint adds a `leg` to the route's details. Requests with 11-25 waypoints are billed at a higher rate. Each route `leg` can be specified with desired fields through a response field mask to return the `duration`, `distanceMeters`, and `legs`.\n"],null,["# Set intermediate waypoints\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\nIntermediate waypoints are locations in between the origin and destination\nthat you want the route to go through. An intermediate waypoint can be a stop or\nyou can specify it as a location to pass through. For an example of a waypoint\nfor a stop, see [Set a stop along a route](/maps/documentation/routes/stop_over). For an example of a\nwaypoint to pass-through,\n[Set point for a route to pass-through](/maps/documentation/routes/pass-through).\n| **Note:** Intermediate waypoints are not supported in the Compute Route Matrix.\n\nUse the `intermediates` array property of the\n[computeRoutes](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes) method (REST) or the\n[ComputeRoutes](/maps/documentation/routes/reference/rpc/google.maps.routing.v2#google.maps.routing.v2.Routes.ComputeRoutes)\nmethod (gRPC), to define up to a maximum of 25 intermediate waypoints.\n| **Caution:** If you make requests using 11 or more intermediate waypoints (between 11 and 25), your requests are billed at a higher rate. [Learn more about billing](/maps/documentation/routes/usage-and-billing) for Routes API.\n\nFor each intermediate waypoint in the request, the\n[Route object](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes#route) (REST) or\n[Route object](/maps/documentation/routes/reference/rpc/google.maps.routing.v2#route) (gRPC) in the\nresponse adds an entry to the `legs` array to provide the details for\nthat leg of the journey.\n\nEach leg of a route is represented by a\n[RouteLeg](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes#routeleg) (REST) or\n[RouteLeg](/maps/documentation/routes/reference/rpc/google.maps.routing.v2#routeleg) (gRPC) object.\nControl which `RouteLeg` fields to return by using the\n[response field mask](/maps/documentation/routes/choose_fields).\n\nExample - Set an intermediate waypoint\n--------------------------------------\n\nThe following example uses the `intermediates` array property to add a single\nintermediate waypoint to the POST request body of a route.\n\nThis example uses a response field mask in the `X-Goog-FieldMask` header\nthat specifies to return the following fields in the response:\n\n- `routes.duration`\n- `routes.distanceMeters`\n- `routes.legs` corresponding to the entire `RouteLeg` object.\n\n```json\ncurl -X POST -d '{\n \"origin\":{\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.419734,\n \"longitude\": -122.0827784\n }\n },\n \"sideOfRoad\": true\n },\n \"destination\":{\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.417670,\n \"longitude\": -122.079595\n }\n }\n },\n \"intermediates\": [\n {\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.419734,\n \"longitude\": -122.0807784\n }\n }\n }\n ],\n \"travelMode\": \"DRIVE\",\n \"routingPreference\": \"TRAFFIC_AWARE\",\n \"departureTime\": \"2022-10-15T15:01:23.045123456Z\",\n \"computeAlternativeRoutes\": false,\n \"routeModifiers\": {\n \"avoidTolls\": false,\n \"avoidHighways\": false,\n \"avoidFerries\": false\n },\n \"languageCode\": \"en-US\",\n \"units\": \"IMPERIAL\"\n}'\n-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY'\n-H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.legs'\n'https://routes.googleapis.com/directions/v2:computeRoutes'\n```\n\nThe response from this call contains the `legs` array. Each step of the leg is\nrepresented by a\n[RouteLegStep](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes#routelegstep) (REST) or\n[RouteLegStep](/maps/documentation/routes/reference/rpc/google.maps.routing.v2#routelegstep) (gRPC) object. \n\n```json\n{\n \"routes\": [\n {\n \"legs\": [\n # First leg\n {\n \"distanceMeters\": 207,\n \"duration\": \"89s\",\n \"staticDuration\": \"89s\",\n \"polyline\": {\n \"encodedPolyline\": \"ipkcFjgchVd@@@cF]@@oCK?\"\n },\n \"startLocation\": {\n \"latLng\": {\n \"latitude\": 37.4197318,\n \"longitude\": -122.0826233\n }\n },\n \"endLocation\": {\n \"latLng\": {\n \"latitude\": 37.419734,\n \"longitude\": -122.08077919999998\n }\n },\n \"steps\": [ {\n \"distanceMeters\": 21,\n \"staticDuration\": \"6s\",\n \"polyline\": {\n \"encodedPolyline\": \"ipkcFjgchVd@@\"\n },\n \"startLocation\": {\n \"latLng\": {\n \"latitude\": 37.4197318,\n \"longitude\": -122.0826233\n }\n },\n \"endLocation\": {\n \"latLng\": {\n \"latitude\": 37.41954,\n \"longitude\": -122.08262750000002\n }\n }\n },\n ...\n },\n # Second leg\n {\n \"distanceMeters\": 598,\n \"duration\": \"159s\",\n \"staticDuration\": \"159s\",\n \"polyline\": {\n \"encodedPolyline\": \"ipkcFz{bhVh@??{@xPBP?J}E{E?\"\n },\n \"startLocation\": {\n \"latLng\": {\n \"latitude\": 37.419734,\n \"longitude\": -122.08077919999998\n }\n },\n \"endLocation\": {\n \"latLng\": {\n \"latitude\": 37.417616599999995,\n \"longitude\": -122.07938820000001\n }\n },\n \"steps\": [\n {\n ...\n```"]]