Route Matrix 클래스로 이전
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
RouteMatrix
클래스는 Distance Matrix Service, Maps JavaScript API (레거시)를 대체합니다.
이 페이지에서는 기존 거리 행렬 서비스와 새로운 JavaScript 라이브러리의 차이점을 설명하고 비교를 위한 코드를 제공합니다.
Distance Matrix API (기존)와 Route Matrix 클래스 (베타) 비교
다음 표에서는 기존 Distance Matrix API와 RouteMatrix
클래스의 요청 매개변수를 비교합니다.
코드 비교
이 섹션에서는 유사한 두 코드 조각을 비교하여 기존 Distance Matrix API와 새 RouteMatrix
클래스의 차이점을 보여줍니다. 코드 스니펫은 경로 요청을 하고 결과를 확인하는 데 각 API에 필요한 코드를 보여줍니다.
Directions API (기존)
다음 코드는 기존 Distance Matrix API를 사용하여 거리 매트릭스 요청을 만듭니다.
// Define the request.
const request = {
origins: [{lat: 55.93, lng: -3.118}, 'Greenwich, England'],
destinations: ['Stockholm, Sweden', {lat: 50.087, lng: 14.421}],
travelMode: 'DRIVING',
drivingOptions: {
departureTime: new Date(Date.now()),
trafficModel: 'optimistic'
}
};
// Make the request.
service.getDistanceMatrix(request).then((response) => {
// Display the response.
document.getElementById("response").textContent = JSON.stringify(
response,
null,
2,
);
});
Route Matrix 클래스 (베타)
다음 코드는 새 경로 매트릭스 클래스를 사용하여 거리 매트릭스 요청을 만듭니다.
// Define the request.
const request = {
origins: [{lat: 55.93, lng: -3.118}, 'Greenwich, England'],
destinations: ['Stockholm, Sweden', {lat: 50.087, lng: 14.421}],
travelMode: 'DRIVING',
departureTime: new Date(),
trafficModel: 'optimistic'
};
// Make the request.
const response = await RouteMatrix.computeRouteMatrix(request);
// Display the response.
document.getElementById("response").setValue(JSON.stringify(response, null, 2,));
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(UTC)
[null,null,["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["**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 `RouteMatrix` class replaces the\n[Distance Matrix Service, Maps JavaScript API (Legacy)](/maps/documentation/javascript/legacy/distancematrix).\nThis page explains the differences between the legacy Distance Matrix service and the new\nJavaScript library, and provides some code for comparison.\n\nDistance Matrix API (Legacy) versus Route Matrix class (Beta)\n\nThe following table compares the request parameters for the legacy\n[Distance Matrix API](/maps/documentation/javascript/reference/next/distance-matrix) and\nthe [`RouteMatrix`](/maps/documentation/javascript/reference/route-matrix) class.\n\n| [Distance Matrix Service (Legacy)](/maps/documentation/javascript/legacy/distancematrix) | [`RouteMatrix`](/maps/documentation/javascript/reference/route-matrix) (Beta) |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Required Parameters** ||\n| [`origins`](/maps/documentation/javascript/legacy/distancematrix) | [`origins`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.origins) |\n| [`destinations`](/maps/documentation/javascript/legacy/distancematrix) | [`destinations`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.destinations) |\n| **Optional Parameters** ||\n| [`travelMode`](/maps/documentation/javascript/legacy/distancematrix) | [`travelMode`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.travelMode) |\n| [`transitOptions`](/maps/documentation/javascript/legacy/distancematrix) | [`transitPreference`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.transitPreference) |\n| [`arrivalTime`](/maps/documentation/javascript/legacy/distancematrix) | [`arrivalTime`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.arrivalTime) |\n| [`drivingOptions`](/maps/documentation/javascript/legacy/distancematrix#driving_options) | [`departureTime`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.departureTime), [`trafficModel`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.traffic_model) |\n| [`unitSystem`](/maps/documentation/javascript/legacy/distancematrix#distance_matrix_requests) | [`units`](/maps/documentation/javascript/reference/route-matrix#ComputeRouteMatrixRequest.units) |\n| [`avoidHighways`](/maps/documentation/javascript/legacy/distancematrix#driving_options), [`avoidTolls`](/maps/documentation/javascript/legacy/distancematrix#driving_options) | [`RouteModifiers`](/maps/documentation/javascript/reference/route-matrix#RouteModifiers) |\n\nCode comparison\n\nThis section compares two similar pieces of code to illustrate the differences between the\nlegacy Distance Matrix API and the new `RouteMatrix` class. The code snippets show\nthe code required on each respective API to make a directions request, and view the results.\n\nDirections API (Legacy)\n\nThe following code makes a distance matrix request using the legacy Distance Matrix API. \n\n```javascript\n// Define the request.\nconst request = {\n origins: [{lat: 55.93, lng: -3.118}, 'Greenwich, England'],\n destinations: ['Stockholm, Sweden', {lat: 50.087, lng: 14.421}],\n travelMode: 'DRIVING',\n drivingOptions: {\n departureTime: new Date(Date.now()),\n trafficModel: 'optimistic'\n }\n};\n\n// Make the request.\nservice.getDistanceMatrix(request).then((response) =\u003e {\n // Display the response.\n document.getElementById(\"response\").textContent = JSON.stringify(\n response,\n null,\n 2,\n );\n});\n \n```\n\nRoute Matrix class (Beta)\n\n\nThe following code makes a distance matrix request using the new Route Matrix class: \n\n```javascript\n// Define the request.\nconst request = {\n origins: [{lat: 55.93, lng: -3.118}, 'Greenwich, England'],\n destinations: ['Stockholm, Sweden', {lat: 50.087, lng: 14.421}],\n travelMode: 'DRIVING',\n departureTime: new Date(),\n trafficModel: 'optimistic'\n};\n\n// Make the request.\nconst response = await RouteMatrix.computeRouteMatrix(request);\n\n// Display the response.\ndocument.getElementById(\"response\").setValue(JSON.stringify(response, null, 2,));\n \n```"]]