ภาพรวมเมทริกซ์เส้นทางของ Compute
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
นักพัฒนาแอปในเขตเศรษฐกิจยุโรป (EEA)
Compute Route Matrix เป็นเมธอดในบริการ Routes API ที่ยอมรับคำขอ HTTPS และแสดงผลระยะทางและเวลาเดินทางสำหรับเมทริกซ์ของเส้นทางระหว่างสถานที่ต้นทางและปลายทางที่แตกต่างกัน คำนวณเวลาในการเดินทางและระยะทางสำหรับหลายๆ จุดหมายปลายทางสำหรับองค์ประกอบเส้นทางได้สูงสุด 625 รายการ
หากต้องการเส้นทางการขับขี่ หากสนใจเส้นทาง ให้ดูภาพรวมเส้นทางใน Compute
หากจะย้ายข้อมูล หากคุณจะย้ายข้อมูลจาก Distance Matrix API (เดิม) ให้ดูวิธีการย้ายข้อมูลโดยเริ่มจากเหตุผลที่ควรย้ายข้อมูลไปยัง Routes API
เหตุผลที่ควรใช้เมทริกซ์เส้นทางของ Compute
การใช้ Compute Route Matrix ช่วยให้คุณระบุเส้นทางที่มีประสิทธิภาพสูงสุดสำหรับการกำหนดเวลาการจัดส่งได้ เช่น
คุณใช้ Compute Route Matrix ทำอะไรได้บ้าง
เมื่อใช้ Compute Route Matrix คุณจะได้รับเมทริกซ์ของเส้นทางที่เป็นไปได้ระหว่างจุดเริ่มต้นและจุดสิ้นสุดหลายแห่ง คุณสามารถระบุต้นทางและปลายทางได้หลายรายการต่อคำขอฝั่งเซิร์ฟเวอร์ โดยจำนวนต้นทางต้องคูณด้วยจำนวนปลายทางไม่เกิน 625 คุณสามารถสตรีมองค์ประกอบของคำตอบได้ก่อนที่จะคำนวณทั้งเมทริกซ์ ซึ่งจะช่วยลดเวลาในการตอบสนอง
คุณสามารถขอข้อมูลเส้นทางประเภทต่อไปนี้เพื่อพิจารณาเส้นทางที่มีประสิทธิภาพสูงสุดในการกำหนดเส้นทางผู้โดยสาร การจัดส่ง หรือคนงานระหว่างต้นทางและปลายทางหลายแห่ง
วิธีการทำงานของ Compute Route Matrix
เมธอด ComputeRouteMatrix
จะยอมรับคําขอ HTTP POST ที่มีตัวข้อมูลคําขอ JSON ซึ่งมีรายละเอียดคําขอ ต้องมีต้นทางอย่างน้อย 1 แห่ง, จุดหมายปลายทาง 2 แห่งขึ้นไป, travelMode และมาสก์ฟิลด์เพื่อระบุฟิลด์ที่จะแสดงผล
ตัวอย่าง
curl -X POST -d '{
"origins": [
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.420761,
"longitude": -122.081356
}
}
}
},
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.403184,
"longitude": -122.097371
}
}
}
}
],
"destinations": [
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.420999,
"longitude": -122.086894
}
}
}
},
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.383047,
"longitude": -122.044651
}
}
}
}
],
"travelMode": "DRIVE"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H 'X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,status,condition' \
'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix'
การตอบกลับจะมีเส้นทางที่เป็นไปได้สำหรับจุดแวะพักต้นทางและปลายทางทั้งหมดที่รวมกัน
แหล่งข้อมูล
ตารางต่อไปนี้สรุปทรัพยากรที่ใช้ได้ผ่านเมธอด Compute Route Matrix ของ Routes API พร้อมข้อมูลที่แสดงผล
แหล่งข้อมูล |
ข้อมูลที่แสดงผล |
รูปแบบการแสดงผล |
ComputeRouteMatrix |
แสดงผลอาร์เรย์ของเส้นทางจากจุดเริ่มต้น 1 จุดไปยังจุดหมาย 1 จุด |
JSON |
วิธีใช้ Compute Route Matrix
ไลบรารีของไคลเอ็นต์ที่ใช้ได้
ดูรายการไลบรารีของไคลเอ็นต์ที่ใช้ได้สำหรับ Compute Route Matrix ได้ที่ไลบรารีของไคลเอ็นต์
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-06-20 UTC
[null,null,["อัปเดตล่าสุด 2025-06-20 UTC"],[],[],null,["# Compute Route Matrix Overview\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\nCompute Route Matrix is a method in the Routes API service that accepts\nan HTTPS request and returns distances and travel times for a matrix of routes\nbetween different origin and destination locations. Calculate travel times and\ndistances for multiple destinations for up to 625 route elements.\n\n**Need Driving Routes?** If you are interested in route directions, see\n[Compute Routes Overview](/maps/documentation/routes/compute-route-over).\n\n**Migrating?** If you are migrating from the Distance Matrix API (Legacy),\nsee migration instructions starting with\n[Why migrate to the Routes API](/maps/documentation/routes/migrate-routes-why).\n\nWhy use Compute Route Matrix\n----------------------------\n\nWith Compute Route Matrix, you can determine the most efficient\nroutes for dispatch scheduling, such as:\n\n- How best to assign a set of workers to pick up a series of packages\n\n- Determine the best warehouse from which to ship packages to their final\n destination\n\nWhat you can do with Compute Route Matrix?\n------------------------------------------\n\nWith Compute Route Matrix, you can get a matrix of possible routes\nbetween many start and end locations. You can specify multiple origins and\ndestinations per server-side request with the number of origins times the number\nof destinations up to 625. You can stream elements of the response before the\nentire matrix has been calculated, lowering response latency.\n\nYou can request these kinds of route data to determine the most efficient way to\nroute passengers, shipments, or workers between multiple origins and\ndestinations:\n\n- **Distance in kilometers or miles for a selected travel mode**\n\n- **Estimated travel time in traffic**\n\nHow Compute Route Matrix works\n------------------------------\n\nThe `ComputeRouteMatrix` method accepts an HTTP POST request with\na JSON request body that contains the request details. Required are at least one\norigin, two or more destinations, travelMode, and a field mask to specify which\nfields to return. \n\n#### Example\n\n```console\ncurl -X POST -d '{\n \"origins\": [\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.420761,\n \"longitude\": -122.081356\n }\n }\n }\n },\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.403184,\n \"longitude\": -122.097371\n }\n }\n }\n }\n ],\n \"destinations\": [\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.420999,\n \"longitude\": -122.086894\n }\n }\n }\n },\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.383047,\n \"longitude\": -122.044651\n }\n }\n }\n }\n ],\n \"travelMode\": \"DRIVE\"\n}' \\\n-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: \u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e' \\\n-H 'X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,status,condition' \\\n'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix'\n```\n\nThe response contains the possible routes for the combination of all origin\nand destination waypoints.\n\n### Resources\n\nThe following table summarizes the resources available through the\nRoutes API Compute Route Matrix method, along with\nthe data it returns.\n\n\u003cbr /\u003e\n\n| Data resources | Data returned | Return format |\n|-----------------------------------------------------------------------|----------------------------------------------------------------------------------|---------------|\n| [ComputeRouteMatrix](/maps/documentation/routes/compute_route_matrix) | Returns an array of routes from one origin waypoint to one destination waypoint. | JSON |\n\n\u003cbr /\u003e\n\nHow to use Compute Route Matrix\n-------------------------------\n\n|---|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 1 | **Get set up** | Start with [Set up your Google Cloud project](/maps/documentation/routes/cloud-setup) and complete the setup instructions that follow. |\n| 2 | **Understand how the Routes API bills** | For information, see [Usage and billing](/maps/documentation/routes/usage-and-billing). |\n| 3 | **Compute matrix of routes and review the response** | For more information, see [Get a route matrix](/maps/documentation/routes/compute_route_matrix) and [Review the route matrix response](/maps/documentation/routes/understand-rm-response). |\n\n### Available client libraries\n\nFor a list of the available client libraries for\nCompute Route Matrix, see\n[Client libraries](/maps/documentation/routes/client-libraries).\n\nWhat's next\n-----------\n\n- [Get a route matrix](/maps/documentation/routes/compute_route_matrix)\n- [Available route matrix options](/maps/documentation/routes/options-rm)\n- [Choose what information to return](/maps/documentation/routes/choose_fields-rm)\n- [Migrate from Distance Matrix API (Legacy)](/maps/documentation/routes/migrate-routes)\n- [Migrate from the Routes API preview to GA](/maps/documentation/routes/migrate-routes-preview)"]]