路線類別總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
簡介
Route 類別提供 computeRoutes
方法,可傳回兩個地點之間的理想路線。提供多個地點之間的大眾運輸、單車、開車、2 輪機動車輛或步行路線和即時路況。
需要路徑矩陣嗎?如要瞭解路徑矩陣,請參閱路徑矩陣類別總覽。
要遷移嗎?如要從 Directions Service (舊版) 遷移至 Route
類別,請參閱「遷移至 Route 類別」。
為什麼要使用 Route 類別?
透過 Route
類別,您可以根據偏好設定車輛或包裹的路線,同時盡量降低成本並提升品質。
Route 類別提供哪些功能?
computeRoutes
方法會傳回兩個地點之間的理想路線。使用 Routes 程式庫,您可以執行下列操作:
- 取得不同交通方式的路線:
- 交通方式:大眾運輸、開車、兩輪車輛、步行或騎單車。
- 一系列路線控點,您可以最佳化這些控點的順序,找出最有效率的路線。
- 使用多種方式指定起點、目的地和途經點:
- 文字字串。例如:「Chicago, IL」、「Darwin, NT, Australia」、「1800 Amphitheatre Parkway, Mountain View, CA 94043」或「CWF6+FWX Mountain View, California」
- 放置執行個體
- 經緯度座標,可選用車輛航向
- 根據需求和目標微調路線選項:
- 根據車輛的引擎類型選取省油路線:
柴油、電動、油電混合、汽油。
- 設定精細的流量計算選項,讓您在品質與延遲之間做出取捨。
- 為路線控點設定車輛行進方向和道路側資訊,提高預計到達時間的準確度。
- 指定直達與終點位置,以及安全中途停留位置。
- 要求取得路線距離和預計抵達時間,以及通行費資訊。
- 控管延遲和品質:使用欄位遮罩只要求所需資料,避免不必要的處理時間和較高的要求計費費率。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間: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)"]]