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.
Mục tiêu là các thông số xác định trước các mục tiêu tối ưu hoá thường gặp, chẳng hạn như khoảng cách hoặc thời gian di chuyển ngắn nhất, giao hàng đúng giờ, cân bằng tải giữa các tài xế. Mục đích của việc này là giúp nhà phát triển dễ dàng sử dụng Route Optimization API trước khi tìm hiểu về các thông số phức tạp và khả năng tuỳ chỉnh đầy đủ của các thông số về chi phí. (Xem phần "cost model" để biết cách tuỳ chỉnh đầy đủ nhiều mục tiêu của bạn)
Khi được đặt, ShipmentModel.objectives sẽ ghi đè hoàn toàn mô hình chi phí, do đó, chúng không tương thích với các chi phí hiện có. Mỗi Objective tương ứng với một số chi phí được xác định trước cho xe, lô hàng hoặc thuộc tính chuyển đổi.
Khi chỉ định chế độ giải TRANSFORM_AND_RETURN_REQUEST, yêu cầu sẽ không được giải quyết mà chỉ được xác thực và điền các chi phí tương ứng với các mục tiêu đã cho. Yêu cầu đã sửa đổi được trả về dưới dạng OptimizeToursResponse.processed_request. Tất cả các chế độ giải khác sẽ trả về yêu cầu đã giải.
Chế độ giải quyết TRANSFORM_AND_RETURN_REQUEST chỉ hợp lệ cho các yêu cầu OptimizeTours và không dùng được cho các yêu cầu khác của Route Optimization API.
Ví dụ: Tạo yêu cầu ShipmentModel.objectives
Trước khi đưa ra yêu cầu, hãy hoàn tất các bước sau:
Đặt PROJECT_NUMBER_OR_ID thành số hoặc mã dự án trên Cloud.
Lệnh sau đây sẽ gửi một OptimizeToursRequest đến Route Optimization API. API này sẽ trả về một OptimizeToursResponse có trường ProcessedRequest được đặt.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[],[],null,["\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\nObjectives are parameters that pre-define common optimization targets, such as\nshortest travel distance or duration, on time deliveries, balancing loads\nbetween drivers. It's meant to make it easier for developers to onboard to Route\nOptimization API before learning the sophications and full customization of cost\nparameters. (See \"[`cost model`](/maps/documentation/route-optimization/concepts/costs)\" for how to fully customize your wide variety of objectives)\n\nWhen set, the [`ShipmentModel.objectives`](/maps/tt/route-optimization/experimental/objectives/reference/rpc/google.maps.routeoptimization.v1#shipmentmodel) overwrite the cost model\ncompletely, therefore they are incompatible with pre-existing costs. Each\n[`Objective`](/maps/tt/route-optimization/experimental/objectives/reference/rpc/google.maps.routeoptimization.v1#objective) maps to a number of predefined costs for vehicles, shipments or\ntransition attributes.\n| **Note:** `OptimizeToursRequests` that have both costs and objectives set are invalid and will be rejected with a validation error.\n\nWhen specifying the [`TRANSFORM_AND_RETURN_REQUEST`](/maps/tt/route-optimization/experimental/objectives/reference/rpc/google.maps.routeoptimization.v1#solvingmode) solving mode,\nthe request is not solved and it is only validated and filled with costs\ncorresponding to the given objectives. The modified request is returned as\n[`OptimizeToursResponse.processed_request`](/maps/tt/route-optimization/experimental/objectives/reference/rpc/google.maps.routeoptimization.v1#optimizetoursresponse). All other solve modes will\nreturn the solved request.\n| **Note:** `TRANSFORM_AND_RETURN_REQUEST` requests are not billed.\n\nThe `TRANSFORM_AND_RETURN_REQUEST` solving mode is only valid for\n`OptimizeTours` requests and is not available for other Route Optimization API\nrequests.\n\nExample: Make a `ShipmentModel.objectives` request\n\nBefore making a request, complete the following steps:\n\n- Ensure you have [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) configured as described in [Use OAuth](/maps/documentation/route-optimization/oauth-token).\n- Set \u003cvar label=\"project_number\" translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e to your Cloud\n project number or ID.\n\n The following command sends an `OptimizeToursRequest` to the\n Route Optimization API which returns an `OptimizeToursResponse`. \n\n ```carbon\n curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/\u003cvar label=\"project_number\" translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e:optimizeTours' \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n --data @- \u003c\u003cEOM\n {\n \"model\": {\n \"shipments\": [\n {\n \"pickups\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.42506261000996,\n \"longitude\": -122.09535511930135\n }\n }\n ],\n \"deliveries\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.42421503206021,\n \"longitude\": -122.09526063135228\n }\n }\n ]\n }\n ],\n \"vehicles\": [\n {\n \"travelMode\": \"DRIVING\",\n }\n ],\n \"objectives\": [\n {\n \"type\": \"MIN_TRAVEL_TIME\"\n }\n ],\n }\n }\n EOM\n ```\n | **Note:** This example uses the `--data @-` to read a request from standard input. Use `--data @`\u003cvar label=\"curl_filename\" translate=\"no\"\u003eFilename\u003c/var\u003e to read from a file.\n\nExample: Make a `TRANSFORM_AND_RETURN_REQUEST` request\n\nBefore making a request, complete the following steps:\n\n- Ensure you have [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) configured as described in [Use OAuth](/maps/documentation/route-optimization/oauth-token).\n- Set \u003cvar label=\"project_number\" translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e to your Cloud\n project number or ID.\n\n The following command sends an `OptimizeToursRequest` to the\n Route Optimization API which returns an `OptimizeToursResponse` with the\n [`ProcessedRequest`](/maps/tt/route-optimization/experimental/objectives/reference/rpc/google.maps.routeoptimization.v1#optimizetoursresponse) field set. \n\n ```carbon\n curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/\u003cvar label=\"project_number\" translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e:optimizeTours' \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n --data @- \u003c\u003cEOM\n {\n \"model\": {\n \"shipments\": [\n {\n \"pickups\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.42506261000996,\n \"longitude\": -122.09535511930135\n }\n }\n ],\n \"deliveries\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.42421503206021,\n \"longitude\": -122.09526063135228\n }\n }\n ]\n }\n ],\n \"vehicles\": [\n {\n \"travelMode\": \"DRIVING\",\n }\n ],\n \"objectives\": [\n {\n \"type\": \"MIN_TRAVEL_TIME\"\n }\n ]\n },\n \"solvingMode\": \"TRANSFORM_AND_RETURN_REQUEST\"\n }\n EOM\n ```\n The previous command will produce a similar response to the following. \n\n ```\n {\n \"processedRequest\": {\n \"model\": {\n \"shipments\": [\n {\n \"pickups\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.425062610009959,\n \"longitude\": -122.09535511930135\n }\n }\n ],\n \"deliveries\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.424215032060211,\n \"longitude\": -122.09526063135228\n }\n }\n ]\n }\n ],\n \"vehicles\": [\n {\n \"travelMode\": \"DRIVING\",\n \"costPerHour\": 30,\n \"costPerTraveledHour\": 330,\n \"costPerKilometer\": 0.2\n }\n ],\n \"objectives\": [\n {\n \"type\": \"MIN_TRAVEL_TIME\"\n }\n ]\n },\n \"solvingMode\": \"TRANSFORM_AND_RETURN_REQUEST\"\n }\n }\n ```\n | **Note:** This example uses the `--data @-` to read a request from standard input. Use `--data @`\u003cvar label=\"curl_filename\" translate=\"no\"\u003eFilename\u003c/var\u003e to read from a file."]]