קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מפתחים באזור הכלכלי האירופי (EEA)
Route Optimization API חושף שתי שיטות:
OptimizeTours היא שיטה סינכרונית שמחזירה מסלול אופטימלי בתגובה ל-OptimizeToursRequest. הלקוחות צריכים לשמור על חיבור פתוח ל-Route Optimization API עד שהבקשה תעובד ויוחזר OptimizeToursResponse או שגיאה.
BatchOptimizeTours היא שיטה אסינכרונית שמקבלת מזהי URI של OptimizeToursRequest אחד או יותר והודעות OptimizeToursResponse תואמות, ומחזירה את שם המשאב של פעולה ממושכת (LRO) (REST, gRPC) שמשמשת לבדיקה אם אצווה הושלמה. המערכת מעבדת את הOptimizeToursRequest ברקע, כך שהלקוחות שומרים על חיבורים פתוחים ל-Route Optimization API רק למשך הזמן שנדרש לשליחת הBatchOptimizeToursRequest או לקריאה ל-GetOperation כדי לבדוק את הסטטוס של ה-LRO. BatchOptimizeTours קורא בקשות מ-Google Cloud Storage וכותב תשובות אליו.
תרחישים לדוגמה
OptimizeTours נוח לפתרון בקשות קטנות ופשוטות, או לבקשות שזמן הפתרון שלהן הוא כמה דקות או פחות. שמירה על חיבורים לטווח ארוך ל-Route Optimization API מגדילה את הסיכון להפרעה לפני שאפשר להחזיר פתרון.
BatchOptimizeTours יכול לטפל בבקשות גדולות יותר ובבקשות עם זמן פתרון ארוך יותר כי הוא לא דורש חיבור לטווח ארוך ל-API של אופטימיזציית מסלולים.
פעולות ממושכות
קוראים את ה-LRO מ-Route Optimization API באמצעות ה-method GetOperation כדי לבדוק את סטטוס ההשלמה של אצווה. האובייקטים האלה כוללים מאפיין done שמציין אם העיבוד של כל האצווה הושלם, ושדה error שמדווח על שגיאות שנתקלו בהן במהלך העיבוד. אם הערך של done הוא true ולא מופיע error, המשמעות היא שהקבוצה הושלמה בהצלחה. הנוכחות של התג error מציינת שחלק מהעיבוד של הקבוצה נכשל או שכולו נכשל.
מחזור החיים האופייני של בקשת BatchOptimizeTours הוא כזה:
שולחים BatchOptimizeToursRequest אל Route Optimization API, שמחזיר את שם המשאב של LRO.
מבצעים פנייה אל הסקר GetOperation עם שם משאב ה-LRO שמוחזר עד שהמאפיינים done או error מופיעים בתגובת ה-LRO.
אם הערך של done הוא true ולא מוצגת שגיאה, צריך לקרוא את OptimizeToursResponses מכתובות ה-URI של Google Cloud Storage שצוינו בבקשה BatchOptimizeTours. אם error מופיע, בודקים את השגיאה, מעדכנים את OptimizeToursRequest בהתאם ב-Google Cloud Storage ומנסים שוב לפי הצורך בהתאם לשגיאה שנצפתה.
אפשר לשלוח בקשות OptimizeTours ו-BatchOptimizeTours במגוון דרכים, משורת הפקודה או באמצעות ספריית לקוח.
[null,null,["עדכון אחרון: 2025-09-04 (שעון 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)"]]