경로에서 정류장 순서 최적화
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
기본적으로 Routes API Compute Routes
메서드는 정차 경유지라고 하는 여러 정차 지점을 사용자가 제공한 순서대로 통과하는 경로를 계산합니다.
Routes API에서 더 효율적인 순서로 정류장을 재정렬하여 제공된 경로를 최적화하도록 할 수 있습니다. 경유지 최적화는 이동 시간을 최적화하지만 가장 효율적인 경로를 결정할 때 거리, 방향 전환 횟수 등 다른 요인도 고려합니다.
경유지를 최적화하려면 다음 단계를 따르세요.
경로의 어떤 경유지에도 via
가 true
로 설정되어 있지 않은지 확인합니다(예: {"address": "Clare,SA", "via": true}
). 중간 경유지에 관한 자세한 내용은 중간 경유지 지정을 참고하세요.
routing_preference
이 TRAFFIC_AWARE_OPTIMAL
으로 설정되지 않았는지 확인합니다.
optimize_waypoint_order
를 true
로 설정합니다. 예를 들면 다음과 같습니다.
"optimizeWaypointOrder": "true",
필드 마스크에서 routes.optimizedIntermediateWaypointIndex
필드를 지정합니다.
REST
-H X-Goog-FieldMask: routes.optimizedIntermediateWaypointIndex
RPC
const (fieldMask = "routes.optimizedIntermediateWaypointIndex")
경유지 순서가 최적화되는 방식 이해하기
Routes API가 경로의 경유지 순서를 최적화하는 방법은 다음과 같습니다.
요청에 제공된 순서에 따라 웨이포인트를 자동으로 색인화합니다(0부터 시작).
요청에서 경유지에 할당된 색인 번호를 사용하여 경유지 순서를 최적화합니다.
routes.optimizedIntermediateWaypointIndex
아래 waypoint_order
필드의 routes
객체에 최적화된 경유지 순서를 반환합니다.
예
이 요청은 사우스오스트레일리아 애들레이드에서 사우스오스트레일리아의 각 주요 와인 지역으로 이동한 후 애들레이드로 돌아오는 경로의 최적화를 요청합니다.
curl -X POST -H 'content-type: application/json' -d ' {
"origin": {
"address": "Adelaide,SA"
},
"destination": {
"address": "Adelaide,SA"
},
"intermediates": [
{"address": "Barossa+Valley,SA"},
{"address": "Clare,SA"},
{"address": "Coonawarra,SA"},
{"address": "McLaren+Vale,SA"}
],
"travelMode": "DRIVE",
"optimizeWaypointOrder": "true"
}' \
-H 'Content-Type: application/json' \
-H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H 'X-Goog-FieldMask: routes,geocodingResults.intermediates.intermediateWaypointRequestIndex' \
'https://routes.googleapis.com/directions/v2:computeRoutes'
Routes API는 요청에 제공된 중간 경유지를 0부터 시작하여 색인화합니다. 예를 들면 다음과 같습니다.
0 {"address": "Barossa+Valley,SA"},
1 {"address": "Clare,SA"},
2 {"address": "Coonawarrav,SA"},
3 {"address": "McLaren+Vale,SA"}
그런 다음 서비스는 요청에 제공된 4개 경유지의 색인 번호를 사용하여 최적화된 순서를 반환합니다.
"optimizedIntermediateWaypointIndex": [
3,
2,
0,
1
]
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-22(UTC)
[null,null,["최종 업데이트: 2025-07-22(UTC)"],[[["\u003cp\u003eThe Routes API's \u003ccode\u003eCompute Routes\u003c/code\u003e method can optimize the order of stops (waypoints) for greater efficiency by considering factors like travel time, distance, and turns.\u003c/p\u003e\n"],["\u003cp\u003eTo enable waypoint optimization, ensure no waypoints are marked as \u003ccode\u003evia\u003c/code\u003e, avoid using \u003ccode\u003eTRAFFIC_AWARE_OPTIMAL\u003c/code\u003e routing preference, and set \u003ccode\u003eoptimizeWaypointOrder\u003c/code\u003e to \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe API indexes waypoints based on their order in the request, optimizes the order, and returns the optimized sequence in the \u003ccode\u003eoptimizedIntermediateWaypointIndex\u003c/code\u003e field.\u003c/p\u003e\n"],["\u003cp\u003eRequests with waypoint optimization are billed at a higher rate on the ComputeRoutes-Advanced SKU.\u003c/p\u003e\n"]]],["The Routes API can optimize the order of stopover waypoints to create a more efficient route. To enable this, set `optimize_waypoint_order` to `true`, ensure no waypoints have `via: true` and the `routing_preference` is not `TRAFFIC_AWARE_OPTIMAL`. The API indexes waypoints, optimizes their order based on factors like travel time and distance, and returns the optimized order in `routes.optimizedIntermediateWaypointIndex`. This optimization is billed at a higher rate.\n"],null,["# Optimize the order of stops on your route\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\nBy default, the Routes API `Compute Routes`\nmethod calculates a route through multiple stops, called stopover waypoints, in\nthe order that you provide them.\n\nYou can have the Routes API optimize the provided route by rearranging\nstops in a more efficient order. Waypoint optimization optimizes for travel\ntime but also considers other factors such as distance and number of turns when\ndeciding which route is the most efficient.\n\nTo optimize waypoints\n---------------------\n\n1. Make sure none of the waypoints in the route have `via` set to `true`, for\n example: `{\"address\": \"Clare,SA\", \"via\": true}`. For more information about\n intermediate waypoints, see\n [Specify intermediate waypoints](/maps/documentation/routes/intermed_waypoints).\n\n2. Make sure the `routing_preference` is not set to `TRAFFIC_AWARE_OPTIMAL`.\n\n3. Set `optimize_waypoint_order` to `true`. For example:\n\n ```json\n \"optimizeWaypointOrder\": \"true\",\n ```\n4. Specify the `routes.optimizedIntermediateWaypointIndex` field in the field\n mask:\n\n **REST** \n\n ```json\n -H X-Goog-FieldMask: routes.optimizedIntermediateWaypointIndex\n ```\n\n **RPC** \n\n ```gdscript\n const (fieldMask = \"routes.optimizedIntermediateWaypointIndex\")\n ```\n\n### Understand how waypoint order is optimized\n\nHere's how the Routes API optimizes the order of waypoints in a route:\n\n1. Automatically indexes the waypoints based on the order you provide\n them in the request, starting with 0.\n\n2. Optimizes the order of the waypoints using the index numbers it\n assigned to the waypoints in the request.\n\n3. Returns the optimized waypoint order in the `routes` object, in the\n `waypoint_order` field, under `routes.optimizedIntermediateWaypointIndex`.\n\n### Example\n\nThis request asks for optimization for a route from Adelaide, South Australia,\nto each of South Australia's main wine regions, and then returning to Adelaide. \n\n```json\ncurl -X POST -H 'content-type: application/json' -d ' {\n \"origin\": {\n \"address\": \"Adelaide,SA\"\n },\n \"destination\": {\n \"address\": \"Adelaide,SA\"\n },\n \"intermediates\": [\n {\"address\": \"Barossa+Valley,SA\"},\n {\"address\": \"Clare,SA\"},\n {\"address\": \"Coonawarra,SA\"},\n {\"address\": \"McLaren+Vale,SA\"}\n ],\n \"travelMode\": \"DRIVE\",\n \"optimizeWaypointOrder\": \"true\"\n }' \\\n-H 'Content-Type: application/json' \\\n-H 'X-Goog-Api-Key: YOUR_API_KEY' \\\n-H 'X-Goog-FieldMask: routes,geocodingResults.intermediates.intermediateWaypointRequestIndex' \\\n'https://routes.googleapis.com/directions/v2:computeRoutes'\n```\n\nThe Routes API indexes the intermediate waypoints provided in the\nrequest, starting at 0. For example: \n\n```json\n0 {\"address\": \"Barossa+Valley,SA\"},\n1 {\"address\": \"Clare,SA\"},\n2 {\"address\": \"Coonawarrav,SA\"},\n3 {\"address\": \"McLaren+Vale,SA\"}\n```\n\nUsing the index numbers for the four waypoints provided in the request, the\nservice then returns the optimized order: \n\n```json\n\"optimizedIntermediateWaypointIndex\": [\n 3,\n 2,\n 0,\n 1\n ]\n```\n| **Caution:** Requests using waypoint optimization are billed at a higher rate on the SKU for Compute Routes Pro. For more details, see [SKU: Routes: Compute Routes Pro](/maps/documentation/routes/usage-and-billing#compute-routes-pro-sku)."]]