[null,null,["最后更新时间 (UTC):2025-04-24。"],[[["\u003cp\u003eWaypoint Optimization, an experimental Routes Preferred feature, helps find the most efficient route by reordering intermediate waypoints for driving, motorcycling, cycling, or walking directions.\u003c/p\u003e\n"],["\u003cp\u003eTo use it, enable the feature through Support, set \u003ccode\u003eoptimizeWaypointOrder\u003c/code\u003e to \u003ccode\u003etrue\u003c/code\u003e in your \u003ccode\u003eComputeRoutes\u003c/code\u003e request, and include \u003ccode\u003eoptimizedIntermediateWaypointIndex\u003c/code\u003e in the field mask.\u003c/p\u003e\n"],["\u003cp\u003eThe response will provide the optimized waypoint order in the \u003ccode\u003eoptimizedIntermediateWaypointIndex\u003c/code\u003e field and may take longer to process, requiring a higher timeout value (e.g., 10 seconds) for \u003ccode\u003eX-Server-Timeout\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUsage limitations include a maximum of 98 waypoints (latitude/longitude) or 25 waypoints (place IDs), all waypoints must be stopovers, and requests with 25+ waypoints have additional distance and travel mode restrictions.\u003c/p\u003e\n"]]],[],null,["# Optimize your route waypoints\n\n\u003cbr /\u003e\n\n| This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](/maps/launch-stages).\n\n\u003cbr /\u003e\n\n| This feature is not enabled by default. If you want to use it, contact [Support](/maps/documentation/routes_preferred/support) with the following information: Estimated ComputeRoutes QPM (queries-per-minute) using waypoint optimization, typical number of waypoints per request, and maximum number of waypoints per request.\n\nWaypoint optimization is a Routes Preferred feature that extends\n[`ComputeRoutes`](/maps/documentation/routes_preferred/reference/rest/v1/TopLevel/computeRoutes).\nIt optimizes the order of the intermediate waypoints in a traveler's route,\nensuring that they travel the most efficient route possible. The `ComputeRoutes`\nimplementation of waypoint optimization supports the following travel modes:\n\n- Driving\n- Motorized two-wheeling\n- Cycling\n- Walking\n\nWhy use waypoint optimization?\n------------------------------\n\nWhen building an app that guides users through a number of waypoints en route to\na destination, it's important that the traveller traverses the waypoints in the\noptimal order. This ensures that the traveller arrives at every waypoint in the\nshortest amount of time.\n\nHow it works\n------------\n\nBy default, `ComputeRoutes` calculates a route through its waypoints, in the order\nin which they were originally provided. You can get `ComputeRoutes` to optimize\nthe route by rearranging the intermediate waypoints into a more efficient order.\nYou'll receive a route with optimized waypoints if you set the\n`optimizeWaypointOrder` field in the request body to `true`.\n\n**Note**: The waypoint optimization calculation is primarily based on travel time,\nbut the feature also takes other factors into consideration, such as distance\nand the number of turns.\n\nGet reordered waypoints\n-----------------------\n\nTo get a route with reordered waypoints, set the boolean field\n`optimizeWaypointOrder` to `true` in the body of your request to\n`ComputeRoutes`. Also, include the field `optimizedIntermediateWaypointIndex`\nin the field mask. The response body contains the optimized waypoint order in\nthe `optimizedIntermediateWaypointIndex` fields.\n\n**Note** : The `optimizedIntermediateWaypointIndex` field returns zero-based\nvalues.\n\nExample request\n---------------\n\nThe following example request supplies a route near the Stanford\nUniversity campus. The route waypoints have been supplied sequentially in the\nrequest. The request contains an origin and a destination, with two intermediate\nwaypoints. \n\n POST /v1alpha:computeRoutes\n Host: routespreferred.googleapis.com\n Content-Type: application/json\n X-Server-Timeout: 10\n X-Goog-Api-Key: YOUR_API_KEY\n X-Goog-FieldMask: routes.optimizedIntermediateWaypointIndex,routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline\n {\n \"origin\":{\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.418956,\n \"longitude\": -122.160815\n }\n }\n },\n \"intermediates\": [\n {\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.4176423,\n \"longitude\":-122.1102246\n }\n }\n },\n {\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.407689,\n \"longitude\": -122.1360597\n }\n }\n }\n ],\n \"destination\":{\n \"location\":{\n \"latLng\":{\n \"latitude\": 37.4032137,\n \"longitude\": -122.0349119\n }\n }\n },\n \"travelMode\": \"DRIVE\",\n \"optimizeWaypointOrder\": true,\n \"routingPreference\": \"TRAFFIC_AWARE\"}\n\nExample response\n----------------\n\nYou can find the reordered intermediate waypoint indexes in the\n`optimizedIntermediateWaypointIndex` fields within the routes object in the\nresponse body. The encoded\n[polyline](/maps/documentation/routes_preferred/reference/rest/Shared.Types/Route#polyline)\nis the same as in\n[Directions API](/maps/documentation/directions/overview) and\n[ComputeRoutes](/maps/documentation/routes_preferred/reference/rest/v1/TopLevel/computeRoutes). \n\n routes {\n distance_meters: 17647\n duration {\n seconds: 1866\n }\n polyline {\n encoded_polyline: \"wkkcFvorhVU{@Ec@C}CG}@Mm@[}@i@y@[[g@_@Tk@BSjCgGfF|D\\\\Pv@Lj@@XaCTeC\\\\aCTs@`ByD`@k@h@e@x@Yh@GtADhBF|@G`AWpAs@lAsAdA{A`BmDr@cBmUqQoS}OyGmFiBsAgEwD}CaCU_@Og@@e@Hy@nGkO~@sBr@cBlDqIlByEp@}AjIfGnBbBHLLd@^p@~ErDfNrKrA~@DIhEeBTQ~AqDlE{KjBgE|FnEh@aAi@`A}FoE~AmD`A}BcAm@mHwFwD}CkLwIsDqCgF_EG[GKnCsDrA_BrC_CnCoBpEkD`EyClCsBcBeBIAkGkH]k@eJmKQKsAuA_@g@wCoDGQmEmFmIqROKaDuHvBkBxAgANCRH^f@v@dBHDD?`AUiBqEhBpEaATMCQYm@wAY]SIOByAfAwBjB_ByDaAwBiCeIA[c@aBqEuNOm@IQbA{c@p@aZFmCTuBLg@Tc@BUAKxOeV~Vy_@nBoDv@_BvAcDzA_EdG{RdC{HtIsY|B{Hx@mDbAuFdBsMbKsv@TaBf@}AdF{Sn@_DJq@Lo@aE`@]GUQmAmAQk@@g@RK`Ce@d@UDEPc@f@cCrAyGJs@X{AbIem@bA{JD_AIaAMg@o@{A_Ad@y@NaCLCsCK_FGI\"\n }\n optimizedIntermediateWaypointIndex: 1\n optimizedIntermediateWaypointIndex: 0\n }\n\nIn this example, notice that optimizing the waypoints reverses their original\norder.\n\nRecommended practices\n---------------------\n\nA request with optimized waypoints takes longer to process than a simple routing\nrequest. As such, we recommend that you set a higher timeout on the method call\nby setting a value for the `X-Server-Timeout` request header to at least ten\nseconds. If you continue to receive timeout errors, you can add another second\nand then try again.\n\nUsage limitations\n-----------------\n\nTo use waypoint optimization, you must follow these usage limitations and\nconditions:\n\n- You can specify up to the usage limit for intermediate waypoints on your\n route:\n\n - Up to 98 waypoints using only latitude and longitude coordinates.\n - Up to 25 waypoints if you specify any waypoints using place IDs.\n- All of your waypoints must be of the type **stopover** . None of your waypoints\n can be of the type **via**.\n\n- You must add `routes.optimizedIntermediateWaypointIndex` to the field\n mask.\n\n- If your request has 25 or more intermediate waypoints, it must also\n adhere to the following conditions:\n\n - The accumulated straight-line distance between all of the waypoints must be\n less than 1,000 km. This distance includes both the origin and the\n destination.\n\n - The travel mode must be DRIVE.\n\nRecommended content\n-------------------\n\n- [Choose Fields to Return](/maps/documentation/routes_preferred/choose_fields)\n- [Use Intermediate Waypoints](/maps/documentation/routes_preferred/intermed_waypoints)"]]