路线类概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
简介
Route 类提供 computeRoutes
方法,用于返回两个位置之间的理想路线。提供多个地点之间的公交、骑行、驾车、两轮机动车或步行路线及实时路况。
需要路线矩阵?如果您对路线矩阵感兴趣,请参阅路线矩阵类概览。
正在迁移?如果您要从 Directions 服务(旧版)迁移到 Route
类,请参阅迁移到 Route 类。
为何使用 Route 类?
借助 Route
类,您可以根据自己的偏好设置车辆或包裹的路线,同时优化成本和质量,并获得各种路线详细信息。
您可以使用 Route 类做些什么?
computeRoutes
方法会返回两个位置之间的理想路线。借助 Routes 库,您可以执行以下操作:
- 获取不同出行方式的路线:
- 交通方式:公交、驾车、两轮车辆、步行或骑车。
- 一系列航点,您可以优化这些航点,以确定前往这些航点的最有效顺序。
- 使用多种方式指定起点、终点和途经点:
- 文本字符串。例如:“Chicago, IL”“Darwin, NT, Australia”“1800 Amphitheatre Parkway, Mountain View, CA 94043”或“CWF6+FWX Mountain View, California”
- 放置实例
- 纬度和经度坐标,可以选择性地包含车辆航向
- 根据您的需求和目标微调路线选项:
- 根据车辆的发动机类型选择省油或省能路线:柴油、电动、混合动力、汽油。
- 设置精细的流量计算选项,让您在质量与延迟之间做出权衡。
- 为途经点设置车辆航向(行驶方向)和道路侧信息,以提高预计到达时间的准确性。
- 指定直达位置与中转位置,以及安全的中途停留位置。
- 请求获取路线距离和预计到达时间 (ETA),以及过路费信息。
- 使用字段掩码仅请求所需的数据,从而控制延迟时间和质量,这有助于避免不必要的处理时间和更高的请求结算费率。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[],[],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[](/maps/documentation/javascript/routes/demo)\n\nIntroduction\n\nThe Route class provides the `computeRoutes` method for returning the ideal\nroute between two locations. Provide directions with real-time traffic for transit,\nbiking, driving, 2-wheel motorized vehicles, or walking between multiple locations.\n\n**Need Route Matrixes?** If you are interested in a route matrix, see\n[Route Matrix class overview](/maps/documentation/javascript/routes/route-matrix-class-overview).\n\n**Migrating?** If you are migrating from the Directions Service (Legacy)\nto the `Route` class, see\n[Migrate to the Route class](/maps/documentation/javascript/routes/routes-js-migration).\n\nWhy use the Route class?\n\nWith the `Route` class, with a wide range of route details you can\nroute your vehicles or packages according to your preferences while optimizing for cost and\nquality.\n\nWhat can you do with the Route class?\n\nThe `computeRoutes` method returns the ideal route between two\nlocations. With the Routes library, you can do the following things:\n\n- **Get directions for different ways to travel** :\n - Modes of transportation: transit, driving, two-wheel vehicles, walking, or bicycling.\n - A series of waypoints that you can optimize for the most efficient order in which to travel to them.\n- **Use multiple ways to specify origins, destinations, and waypoints** :\n - Text strings. For example: \"Chicago, IL\", \"Darwin, NT, Australia\", \"1800 Amphitheatre Parkway, Mountain View, CA 94043\", or \"CWF6+FWX Mountain View, California\"\n - Place instances\n - Latitude and longitude coordinates, optionally with vehicle heading\n- **Fine-tune your route options** based on your needs and goals:\n - Select fuel or energy-efficient routes for your vehicle's engine type: Diesel, Electric, Hybrid, Gas.\n - Set fine-grained options for traffic calculation, letting you make quality versus latency trade off decisions.\n - Set vehicle heading (direction of travel) and side-of-road information for waypoints to increase ETA accuracy.\n - Specify pass-through versus terminal locations and safe stopover locations.\n - Request toll information, along with route distance and ETA.\n- **Control your latency and quality** by requesting only the data you need using a field mask, which helps you avoid unnecessary processing time and higher request billing rates.\n\nNext steps\n\n- [Try the demo](/maps/documentation/javascript/routes/demo)\n- [Get started](/maps/documentation/javascript/routes/start)\n- [Get a route](/maps/documentation/routes/get-a-route)\n- [Reference documentation](/maps/documentation/javascript/reference/route)"]]