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)
Route Optimization API cung cấp 2 phương thức:
OptimizeTours là một phương thức đồng bộ trả về một tuyến đường được tối ưu hoá để phản hồi một OptimizeToursRequest. Các ứng dụng phải duy trì một kết nối mở với API Tối ưu hoá tuyến đường cho đến khi yêu cầu được xử lý và trả về OptimizeToursResponse hoặc lỗi.
BatchOptimizeTours là một phương thức không đồng bộ chấp nhận URI cho một hoặc nhiều OptimizeToursRequest và thông báo OptimizeToursResponse tương ứng, trả về tên tài nguyên của một Thao tác diễn ra trong thời gian dài (LRO) (REST, gRPC) được dùng để kiểm tra xem lô đã hoàn tất hay chưa. OptimizeToursRequest được xử lý ở chế độ nền, vì vậy, các ứng dụng duy trì kết nối mở với API Tối ưu hoá tuyến đường chỉ đủ lâu để gửi BatchOptimizeToursRequest hoặc gọi GetOperation để kiểm tra trạng thái LRO. BatchOptimizeTours đọc các yêu cầu và ghi các phản hồi vào Google Cloud Storage.
Trường hợp sử dụng
OptimizeTours rất phù hợp để giải quyết các yêu cầu nhỏ và đơn giản, hoặc các yêu cầu có thời gian giải quyết từ vài phút trở xuống. Việc duy trì các kết nối liên tục với Route Optimization API làm tăng nguy cơ bị gián đoạn trước khi có thể trả về một giải pháp.
BatchOptimizeTours có thể xử lý các yêu cầu lớn hơn và các yêu cầu có thời gian giải quyết lâu hơn vì không yêu cầu kết nối lâu dài với API Tối ưu hoá tuyến đường.
Thao tác thực hiện lâu
LRO được đọc từ Route Optimization API bằng phương thức GetOperation để kiểm tra trạng thái hoàn thành của một lô. LRO bao gồm một thuộc tính done cho biết liệu quá trình xử lý toàn bộ lô đã hoàn tất hay chưa và một trường error báo cáo các lỗi gặp phải trong quá trình xử lý. Nếu done là đúng và không có error, thì tức là lô đã hoàn tất thành công. Sự xuất hiện của error cho biết một phần hoặc toàn bộ lô không xử lý được.
Sau đây là vòng đời điển hình của một yêu cầu BatchOptimizeTours:
Gửi một BatchOptimizeToursRequest đến Route Optimization API. API này sẽ trả về tên tài nguyên của một LRO.
Thăm dò ý kiến GetOperation bằng tên tài nguyên LRO được trả về cho đến khi các thuộc tính done hoặc error xuất hiện trong phản hồi LRO.
Nếu done là true và không có lỗi, hãy đọc OptimizeToursResponses từ các URI Google Cloud Storage được chỉ định trong yêu cầu BatchOptimizeTours. Nếu có error, hãy kiểm tra lỗi, cập nhật OptimizeToursRequest cho phù hợp trong Google Cloud Storage và thử lại nếu thích hợp, tuỳ thuộc vào lỗi đã gặp.
Bạn có thể gửi yêu cầu OptimizeTours và BatchOptimizeTours theo nhiều cách, từ dòng lệnh hoặc bằng cách sử dụng một thư viện ứng dụng.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eThe Route Optimization API offers two methods: \u003ccode\u003eOptimizeTours\u003c/code\u003e for synchronous processing of smaller, simpler requests and \u003ccode\u003eBatchOptimizeTours\u003c/code\u003e for asynchronous handling of larger, more complex requests.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eOptimizeTours\u003c/code\u003e requires an open connection until a response is received, while \u003ccode\u003eBatchOptimizeTours\u003c/code\u003e utilizes Google Cloud Storage for requests and responses, enabling background processing.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eBatchOptimizeTours\u003c/code\u003e relies on Long Running Operations (LROs) to track batch progress, which can be monitored via the \u003ccode\u003eGetOperation\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eWhen using \u003ccode\u003eBatchOptimizeTours\u003c/code\u003e, users should submit the request, poll for completion using the LRO, and retrieve results or address errors as indicated by the LRO status.\u003c/p\u003e\n"]]],[],null,["# Synchronous and asynchronous endpoints\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\nThe Route Optimization API exposes two methods:\n\n- `OptimizeTours` is a *synchronous* method that returns an optimized route in response to an `OptimizeToursRequest`. Clients must maintain an open connection to the Route Optimization API until the request is processed and an `OptimizeToursResponse` or error is returned.\n- `BatchOptimizeTours` is an *asynchronous* method that accepts URIs for one or more `OptimizeToursRequest` and corresponding `OptimizeToursResponse` messages, returning the resource name of a *Long Running Operation* (LRO) ([REST](/maps/documentation/route-optimization/reference/rest/v1/projects.locations.operations#Operation), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.longrunning#google.longrunning.Operations))) that is used to check for batch completion. `OptimizeToursRequest`s are processed in the background, so clients maintain an open connections to the Route Optimization API only long enough to submit the `BatchOptimizeToursRequest` or to call `GetOperation` to check LRO status. `BatchOptimizeTours` reads requests from and writes responses to [Google Cloud Storage](https://cloud.google.com/storage).\n\nUse cases\n---------\n\n`OptimizeTours` is convenient for solving small and simple requests, or for\nrequests with solving times of a few minutes or less. Maintaining long-lived\nconnections to the Route Optimization API increases risk of interruption before\na solution can be returned.\n\n`BatchOptimizeTours` can handle larger requests and requests with longer solving\ntime because it does not require a long-lived connection to the Route\nOptimization API.\n\nLong running operations\n-----------------------\n\nLROs are read from the Route Optimization API using the `GetOperation` method to\ncheck the completion status of a batch. LROs include a `done` property that\nindicates whether processing of the entire batch is complete and an `error`\nfield that reports errors encountered during processing. If `done` is true and\nno `error` is present, the batch completed successfully. The presence of an\n`error` indicates that some or all of the batch failed processing.\n| **Note:** REST `GetOperation` responses omit the `done` property if its value is false and the `error` property if no errors occurred.\n\nThe typical lifecycle of a `BatchOptimizeTours` request is as follows:\n\n1. Submit a `BatchOptimizeToursRequest` to the Route Optimization API, which returns the resource name of an LRO.\n2. Poll `GetOperation` with the returned LRO resource name until the `done` or `error` properties appear in the LRO response.\n3. If `done` is true and no error is present, read `OptimizeToursResponses` from the Google Cloud Storage URIs specified in the `BatchOptimizeTours` request. If `error` is present, inspect the error, update the `OptimizeToursRequest`s accordingly in Google Cloud Storage, and retry as appropriate depending on the observed error.\n\nYou can send `OptimizeTours` and `BatchOptimizeTours` requests in a variety of\nways, either from the command line or using a client library.\n\n[Next: Make an API Request](/maps/documentation/route-optimization/make-request)"]]