สร้างข้อความคําขอ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
นักพัฒนาแอปในเขตเศรษฐกิจยุโรป (EEA)
ดังที่อธิบายไว้โดยย่อในภาพรวมการเพิ่มประสิทธิภาพเส้นทาง คำขอพื้นฐาน
ประกอบด้วยโมเดล การจัดส่ง และยานพาหนะเป็นเอนทิตีที่จำเป็น
- โมเดลจะบันทึกการตั้งค่าและข้อจำกัดสำหรับคำขอทั้งหมด
รวมถึงทั้ง
Shipments
และ Vehicles
- การจัดส่งแสดงถึงงานหรือการจัดส่งจริงที่รวมถึงการรับและการนำส่ง
VisitRequest
การจัดส่งมีการตั้งค่าและข้อจำกัดในพื้นที่
- ยานพาหนะแสดงถึงยานพาหนะ คนขับ หรือบุคลากร ยานพาหนะยังมี
การตั้งค่าและข้อจำกัดในพื้นที่ด้วย
พร็อพเพอร์ตี้ของเอนทิตีแต่ละรายการจะอธิบายส่วนหนึ่งของปัญหาการเพิ่มประสิทธิภาพที่
ความละเอียดระดับหนึ่ง ข้อจำกัดระดับโมเดลจะมีผลกับการจัดส่งและยานพาหนะทั้งหมด ส่วนข้อจำกัดและพร็อพเพอร์ตี้ที่ระบุในการจัดส่งหรือยานพาหนะจะมีผลกับการจัดส่งหรือยานพาหนะรายการเดียว
ดูเอกสารประกอบฉบับสมบูรณ์เกี่ยวกับข้อความแต่ละประเภทได้ในเอกสารอ้างอิง
สำหรับข้อความ ShipmentModel
(REST, gRPC), Shipment
(REST, gRPC)
และ Vehicle
(REST, gRPC)
ที่พัก OptimizeToursRequest
แห่ง
พร็อพเพอร์ตี้ที่ใช้กันโดยทั่วไปของข้อความ OptimizeToursRequest
ระดับบนสุด
(REST, gRPC) มีดังนี้
searchMode
ระบุว่าจะแสดงผลโซลูชันแรกที่ตรงตามข้อจำกัดที่ระบุ หรือค้นหาโซลูชันที่ดีที่สุดเท่าที่จะเป็นไปได้ภายในกำหนดเวลาที่ตั้งไว้
considerRoadTraffic
กำหนดว่าจะใช้การจราจรแบบเรียลไทม์หรือไม่
สำหรับการกำหนดเส้นทางและการประมาณเวลาถึงโดยประมาณ
populateTransitionPolylines
กำหนดว่าจะแสดงผลเส้นประกอบของเส้นทางและโทเค็นเส้นทางในการตอบกลับหรือไม่
พร็อพเพอร์ตี้ของโมเดล
พร็อพเพอร์ตี้ที่ใช้กันโดยทั่วไปของShipmentModel
ข้อความ (REST,
gRPC) มีดังนี้
globalStartTime
แสดงเวลาเริ่มต้นที่เร็วที่สุดของเส้นทางในยานพาหนะและการจัดส่งทั้งหมด
ยานพาหนะจะเริ่มการเปลี่ยนรุ่นและการจัดส่งครั้งแรกก่อนเวลานี้ไม่ได้
globalEndTime
แสดงเวลาสิ้นสุดล่าสุดของเส้นทางในยานพาหนะ
และการจัดส่งทั้งหมด การจัดส่งและการเปลี่ยนทั้งหมดที่กำหนดต้องเสร็จสมบูรณ์
ก่อนเวลานี้
พร็อพเพอร์ตี้การจัดส่ง
พร็อพเพอร์ตี้ที่ใช้กันโดยทั่วไปของShipment
ข้อความ (REST, gRPC)
มีดังนี้
pickups[]
และ deliveries[]
แสดงตำแหน่งที่รับ
หรือนำส่งพัสดุได้ พร็อพเพอร์ตี้ pickups[]
และ deliveries[]
ใช้ข้อความ VisitRequest
(REST, gRPC)
loadDemands
แสดงถึงน้ำหนักที่จำเป็นสำหรับยานพาหนะในการจัดส่งให้เสร็จสมบูรณ์ พร็อพเพอร์ตี้ load_limits
(REST, gRPC)
ที่เกี่ยวข้องของยานพาหนะแสดงถึงปริมาณการโหลดที่ยานพาหนะรองรับได้ในครั้งเดียว
อ่านเพิ่มเติมเกี่ยวกับภาระงานในความต้องการและขีดจำกัดของภาระงาน
penalty_cost
แสดงถึงค่าใช้จ่ายที่เกิดขึ้นหากมีการข้ามการจัดส่ง อ่านข้อมูลเพิ่มเติมเกี่ยวกับค่าใช้จ่ายได้ในพารามิเตอร์โมเดลต้นทุน
พร็อพเพอร์ตี้ยานพาหนะ
พร็อพเพอร์ตี้ที่ใช้กันโดยทั่วไปของVehicle
ข้อความ (REST, gRPC)
มีดังนี้
startLocation
แสดงจุดที่ยานพาหนะต้องเริ่มเส้นทาง พร็อพเพอร์ตี้นี้
ไม่บังคับ หากไม่ได้ระบุไว้ เส้นทางของยานพาหนะจะเริ่มต้นที่
ตำแหน่งของการจัดส่งแรกที่กำหนด
endLocation
แสดงตำแหน่งที่ยานพาหนะต้องสิ้นสุดเส้นทาง พร็อพเพอร์ตี้นี้
ไม่บังคับ หากไม่ได้ระบุไว้ เส้นทางของยานพาหนะจะสิ้นสุดที่ตำแหน่งของ
การจัดส่งที่กำหนดล่าสุด
startTimeWindows[]
แสดงเวลาที่ยานพาหนะเริ่มเส้นทางได้ พร็อพเพอร์ตี้นี้
ไม่บังคับ
endTimeWindows[]
แสดงเวลาที่ยานพาหนะเริ่มและสิ้นสุดเส้นทางได้
ทั้ง 2 พร็อพเพอร์ตี้เป็นพร็อพเพอร์ตี้ที่ไม่บังคับ
loadLimits
แสดงความจุของยานพาหนะที่พร้อมให้บริการเพื่อตอบสนองความต้องการในการโหลดของการจัดส่ง
อ่านเพิ่มเติมเกี่ยวกับความต้องการโหลดและขีดจำกัดได้ในความต้องการโหลดและขีดจำกัด
คำขอตัวอย่างที่สมบูรณ์ในรูปแบบ JSON มีลักษณะดังนี้
{
"model": {
"shipments": [
{
"pickups": [
{
"arrivalLocation": {
"latitude": 37.73881799999999,
"longitude": -122.4161
}
}
],
"deliveries": [
{
"arrivalLocation": {
"latitude": 37.79581,
"longitude": -122.4218856
}
}
]
}
],
"vehicles": [
{
"startLocation": {
"latitude": 37.73881799999999,
"longitude": -122.4161
},
"endLocation": {
"latitude": 37.73881799999999,
"longitude": -122.4161
},
"costPerKilometer": 1.0
}
],
"globalStartTime": "2024-02-13T00:00:00.000Z",
"globalEndTime": "2024-02-14T06:00:00.000Z"
}
}
OptimizeTours
และ BatchOptimizeTours
ทั้งคู่ใช้ข้อความคำขอเช่นเดียวกับ
ตัวอย่างข้างต้น แต่ในลักษณะที่แตกต่างกัน ก่อนที่จะส่งคำขอการเพิ่มประสิทธิภาพเส้นทาง
คุณควรเข้าใจความแตกต่างระหว่าง 2 วิธีต่อไปนี้
การเปรียบเทียบ OptimizeTours และ BatchOptimizeTours
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eRoute Optimization requests require defining a \u003ccode\u003eModel\u003c/code\u003e with \u003ccode\u003eShipments\u003c/code\u003e and \u003ccode\u003eVehicles\u003c/code\u003e to represent the optimization problem.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eModel\u003c/code\u003e sets global parameters, while \u003ccode\u003eShipments\u003c/code\u003e and \u003ccode\u003eVehicles\u003c/code\u003e have individual properties and constraints for pickups, deliveries, loads, and time windows.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eOptimizeToursRequest\u003c/code\u003e allows controlling the search mode, traffic considerations, and response details.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eOptimizeTours\u003c/code\u003e and \u003ccode\u003eBatchOptimizeTours\u003c/code\u003e offer synchronous and asynchronous request processing, respectively, with key differences in handling large or complex scenarios.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify global start and end times for all vehicles and shipments within the \u003ccode\u003eShipmentModel\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Construct a request message\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\nAs briefly described in [Route Optimization Overview](/maps/documentation/route-optimization/overview), a basic request\nconsists of **Model** , **Shipments** , and **Vehicles** as required entities:\n\n- **Model** captures settings and constraints for the entire request, inclusive of both `Shipments` and `Vehicles`.\n- **Shipments** represent tasks or actual shipments that include pickup and delivery `VisitRequest`s. Shipments have local settings and constraints.\n- **Vehicles** represent vehicles, drivers, or personnel. Vehicles also have local settings and constraints.\n\nEach entity's properties describe part of an optimization problem at a\nparticular level of granularity. Model-wide constraints are applied to all\nshipments and vehicles, while constraints and properties specified on shipments\nor vehicles are specific to a single shipment or vehicle.\n\nFor complete documentation on each message type, see the reference documentation\nfor `ShipmentModel` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.ShipmentModel)), `Shipment` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Shipment)),\nand `Vehicle` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Vehicle)) messages.\n\n`OptimizeToursRequest` properties\n---------------------------------\n\nSome commonly used properties of the top-level `OptimizeToursRequest` message\n([REST](/maps/documentation/route-optimization/reference/rest/v1/projects/optimizeTours), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.OptimizeToursRequest)) include the following:\n\n- `searchMode` indicates whether to return the first solution that satisfies specified constraints or find the best possible solution within a set deadline.\n- `considerRoadTraffic` determines whether or not live traffic is used for routing and ETA estimation.\n- `populateTransitionPolylines` determines whether or not route polylines and route tokens are returned in the response.\n\nModel properties\n----------------\n\nSome commonly used properties of the `ShipmentModel` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel),\n[gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.ShipmentModel)) include:\n\n- `globalStartTime` represents the earliest start time of routes across all vehicles and shipments. No vehicle may start its first transitions and shipments before this time.\n- `globalEndTime` represents the latest end time of routes across all vehicles and shipments. All assigned shipments and transitions must be complete before this time.\n\nShipment properties\n-------------------\n\nSome commonly used properties of the `Shipment` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Shipment), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Shipment))\ninclude:\n\n- `pickups[]` and `deliveries[]` represent where a shipment can be picked up or dropped off. `pickups[]` and `deliveries[]` properties both use the `VisitRequest` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#VisitRequest), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Shipment.VisitRequest)).\n- `loadDemands` represent the load required for a vehicle to complete a shipment. Vehicles' corresponding `load_limits` ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle.FIELDS.load_limits), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Vehicle.FIELDS.repeated.google.maps.routeoptimization.v1.Vehicle.LoadLimitsEntry.google.maps.routeoptimization.v1.Vehicle.load_limits)) property represents how much load a vehicle can accommodate at one time. Read more about load in [Load Demands and Limits](/maps/documentation/route-optimization/load-demands-limits).\n- `penalty_cost` represents the cost incurred if a shipment is skipped. Read more on costs in [Cost Model Parameters](/maps/documentation/route-optimization/cost-model).\n\nVehicle properties\n------------------\n\nSome commonly used properties of the `Vehicle` message ([REST](/maps/documentation/route-optimization/reference/rest/v1/ShipmentModel#Vehicle), [gRPC](/maps/documentation/route-optimization/reference/rpc/google.maps.routeoptimization.v1#google.maps.routeoptimization.v1.Vehicle))\ninclude:\n\n- `startLocation` represents where a vehicle must start its route. This property is optional. If not specified, the vehicle's route starts at the location of its first assigned shipment.\n- `endLocation` represents where a vehicle must end its route. This property is optional. If not specified, the vehicle's route ends at the location of its last assigned shipment.\n- `startTimeWindows[]` represents when a vehicle can start its route. This property is optional.\n- `endTimeWindows[]` represents when a vehicle can start and end its route. Both properties are optional.\n- `loadLimits` represent the vehicle's capacity available to meet shipments' load demands. Read more about load demands and limits in [Load Demands and\n Limits](/maps/documentation/route-optimization/load-demands-limits).\n\nA complete example request in JSON format looks like: \n\n {\n \"model\": {\n \"shipments\": [\n {\n \"pickups\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.73881799999999,\n \"longitude\": -122.4161\n }\n }\n ],\n \"deliveries\": [\n {\n \"arrivalLocation\": {\n \"latitude\": 37.79581,\n \"longitude\": -122.4218856\n }\n }\n ]\n }\n ],\n \"vehicles\": [\n {\n \"startLocation\": {\n \"latitude\": 37.73881799999999,\n \"longitude\": -122.4161\n },\n \"endLocation\": {\n \"latitude\": 37.73881799999999,\n \"longitude\": -122.4161\n },\n \"costPerKilometer\": 1.0\n }\n ],\n \"globalStartTime\": \"2024-02-13T00:00:00.000Z\",\n \"globalEndTime\": \"2024-02-14T06:00:00.000Z\"\n }\n }\n\n`OptimizeTours` and `BatchOptimizeTours` both consume request messages like the\nexample above, but in different ways. Before making a Route Optimization\nrequest, it's important to understand the difference between the two methods:\n\n[Comparing OptimizeTours and BatchOptimizeTours](/maps/documentation/route-optimization/sync-vs-async)"]]