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)
Compute Route Matrix là một phương thức trong dịch vụ Routes API, chấp nhận yêu cầu HTTPS và trả về khoảng cách cũng như thời gian di chuyển cho một ma trận các tuyến đường giữa các vị trí xuất phát và đích đến khác nhau. Tính toán thời gian và khoảng cách di chuyển cho nhiều điểm đến với tối đa 625 phần tử tuyến đường.
Bạn có đang di chuyển không? Nếu bạn đang di chuyển từ Distance Matrix API (cũ), hãy xem hướng dẫn di chuyển bắt đầu từ Lý do nên di chuyển sang Routes API.
Lý do nên sử dụng Compute Route Matrix
Với Compute Route Matrix, bạn có thể xác định các tuyến đường hiệu quả nhất để lập lịch điều phối, chẳng hạn như:
Cách tốt nhất để chỉ định một nhóm nhân viên đến lấy một loạt gói hàng
Xác định kho hàng phù hợp nhất để vận chuyển các gói hàng đến điểm đến cuối cùng
Những việc bạn có thể làm với Compute Route Matrix
Với Compute Route Matrix, bạn có thể nhận được một ma trận gồm các tuyến đường có thể có giữa nhiều vị trí bắt đầu và kết thúc. Bạn có thể chỉ định nhiều điểm xuất phát và điểm đến cho mỗi yêu cầu phía máy chủ, với số lượng điểm xuất phát nhân với số lượng điểm đến tối đa là 625. Bạn có thể truyền trực tuyến các phần tử của phản hồi trước khi toàn bộ ma trận được tính toán, giảm độ trễ phản hồi.
Bạn có thể yêu cầu những loại dữ liệu về tuyến đường này để xác định cách hiệu quả nhất để định tuyến hành khách, lô hàng hoặc nhân viên giữa nhiều điểm xuất phát và điểm đến:
Quãng đường tính bằng ki-lô-mét hoặc dặm cho một phương thức di chuyển đã chọn
Thời gian di chuyển ước tính trong điều kiện giao thông
Cách hoạt động của Compute Route Matrix
Phương thức ComputeRouteMatrix chấp nhận yêu cầu HTTP POST có nội dung yêu cầu JSON chứa thông tin chi tiết về yêu cầu. Bạn phải có ít nhất một nguồn, hai hoặc nhiều đích đến, travelMode và một mặt nạ trường để chỉ định những trường cần trả về.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-04 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)"]]