路线产品使用入门
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
按照以下步骤设置 Routes Library,Maps JavaScript API
获取 API 密钥并启用 Maps JavaScript API
在使用 Routes 库(Maps JavaScript API)之前,您需要拥有已关联结算账号的 Cloud 项目,并启用 Maps JavaScript API 和 Routes API。如需了解详情,请参阅设置您的 Google Cloud 项目。
获取 API 密钥
启用 Maps JavaScript API
启用 Routes API
更新地图初始化代码
- 加载 Maps JavaScript API。
- 根据需要在
async
函数中加载 Routes 库:
const { Route, RouteMatrix } = await google.maps.importLibrary('routes');
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-05。
[null,null,["最后更新时间 (UTC):2025-09-05。"],[],[],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\nFollow these steps to get set up with Routes Library, Maps JavaScript API\n\nGet an API key and enable the Maps JavaScript API \nBefore using the Routes Library, Maps JavaScript API,\nyou need a Cloud project with a billing account, and both the\nMaps JavaScript API and Routes API enabled. To\nlearn more, see [Set up your Google Cloud project](/maps/documentation/javascript/cloud-setup).\n[Get an API key](/maps/documentation/javascript/get-api-key)\n\n\n[Enable the Maps JavaScript API](https://console.cloud.google.com/apis/library/maps-backend.googleapis.com)\n\n\n[Enable the Routes API](https://console.cloud.google.com/apis/library/routes.googleapis.com)\n\nUpdate your map initialization code\n\n1. [Load the\n Maps JavaScript API](/maps/documentation/javascript/load-maps-js-api).\n2. Load the Routes library from within an `async` function when needed:\n\n```javascript\n const { Route, RouteMatrix } = await google.maps.importLibrary('routes');\n \n```\n\nNext steps\n\n- [Route class overview](/maps/documentation/javascript/routes/route-class-overview)\n- [Migrate to the new Route class](/maps/documentation/javascript/routes/routes-js-migration)\n- [Route Matrix class overview](/maps/documentation/javascript/routes/route-matrix-class-overview)\n- [Migrate to the new Route Matrix class](/maps/documentation/javascript/routes/route-matrix-js-migration)"]]