중간 지점 최적화는 ComputeRoutes를 확장하는 경로 우선 기능입니다.
여행자의 경로에서 중간 경유지의 순서를 최적화하여 최대한 효율적인 경로를 이동할 수 있도록 합니다. 중간 지점 최적화의 ComputeRoutes 구현은 다음과 같은 이동 수단을 지원합니다.
운전
오토바이
자전거
산책
중간 지점 최적화를 사용해야 하는 이유
사용자를 목적지로 가는 도중에 여러 개의 중간 지점을 통해 안내하는 앱을 빌드할 때는 여행자가 중간 지점을 최적의 순서로 통과하는 것이 중요합니다. 이렇게 하면 여행자가 가장 짧은 시간에 모든 중간 지점에 도착할 수 있습니다.
작동 방식
기본적으로 ComputeRoutes는 경유지를 통해 경로를 계산하며, 이때 경유지는 원래 제공된 순서대로 계산됩니다. 중간 경유지를 더 효율적인 순서로 재정렬하여 ComputeRoutes가 경로를 최적화하도록 할 수 있습니다.
요청 본문의 optimizeWaypointOrder 필드를 true로 설정하면 최적화된 경유지가 포함된 경로가 반환됩니다.
참고: 중간 지점 최적화 계산은 주로 이동 시간을 기반으로 하지만 거리, 방향 전환 횟수와 같은 다른 요소도 고려됩니다.
재정렬된 웨이포인트 가져오기
재정렬된 웨이포인트가 포함된 경로를 가져오려면 요청 본문에서 불리언 필드 optimizeWaypointOrder를 true로 설정하고 ComputeRoutes로 설정합니다. 또한 필드 마스크에 optimizedIntermediateWaypointIndex 필드를 포함합니다. 응답 본문에는 optimizedIntermediateWaypointIndex 필드에 최적화된 중간 지점 순서가 포함됩니다.
참고: optimizedIntermediateWaypointIndex 필드는 0부터 시작하는 값을 반환합니다.
요청 예시
다음 요청 예에서는 스탠퍼드 대학교 캠퍼스 근처의 경로를 제공합니다. 경로 웨이포인트가 요청에 순차적으로 제공되었습니다. 요청에는 출발지와 목적지가 있으며 중간 경유지가 2개 있습니다.
최적화된 경유지가 있는 요청은 간단한 경로 탐색 요청보다 처리하는 데 시간이 더 오래 걸립니다. 따라서 X-Server-Timeout 요청 헤더의 값을 10초 이상으로 설정하여 메서드 호출의 제한 시간을 더 높게 설정하는 것이 좋습니다. 제한 시간 오류가 계속 발생하면 1초를 더 추가한 후 다시 시도해 볼 수 있습니다.
사용 제약사항
중간 지점 최적화를 사용하려면 다음과 같은 사용 제한사항 및 조건을 따라야 합니다.
경로의 중간 웨이포인트 사용량 제한을 최대 10개까지 지정할 수 있습니다.
위도와 경도 좌표만 사용하는 최대 98개의 웨이포인트
장소 ID를 사용하여 와이포인트를 지정하는 경우 최대 25개의 와이포인트
모든 경유지가 중간 기착지 유형이어야 합니다. via 유형의 중간 지점은 사용할 수 없습니다.
[null,null,["최종 업데이트: 2025-04-24(UTC)"],[[["\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)"]]