這項產品或功能已進入舊版狀態。如要進一步瞭解舊版狀態,以及如何從舊版遷移至新版服務,請參閱「
舊版產品和功能」。
Directions API (舊版) 總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。

Directions API (舊版) 是一項服務,可接受 HTTP 要求,並傳回地點間的 JSON 或 XML 格式路線。
使用 Directions API 的好處
透過 Directions API,您可以取得多種交通方式的路線,例如大眾運輸、開車、步行或騎自行車。
Directions API 的用途
您可以使用 Directions API 計算地點之間的路線,包括下列詳細資料:
- 多種交通方式的路線,包括大眾運輸、開車、步行或騎單車。
- 使用一系列路線控點的多段路線。
- 以多種方式指定起點、目的地和路線控點,包括文字字串 (例如「伊利諾州芝加哥」或「澳洲北領地達爾文」)、地點 ID 或經緯度座標。
Directions API 的運作方式
計算路線時,Directions API 會傳回最有效率的路線。產品在判斷最有效率的路線時,會考量下列旅遊元素:
以下範例要求會以 JSON 格式傳回從安大略省多倫多到魁北克省蒙特婁的行車路線:
https://maps.googleapis.com/maps/api/directions/json
?destination=Montreal
&origin=Toronto
&key=YOUR_API_KEY
資源
下表概略說明 Directions API 提供的資源,以及傳回的資料。
資料資源 |
傳回的資料 |
傳回格式 |
路線
以地點 ID、地址或經緯度座標的形式提供起點和目的地。詳情請參閱必要參數。
|
詳細路線指示,包括路線、路段和步驟。詳情請參閱「路線指引回應」。 |
|
如何使用 Directions API
1 |
完成設定。 |
請先按照「設定 Google Cloud 專案」一文中的操作說明完成設定, |
2 |
立即試用 |
取得 API 金鑰和雲端專案後,即可免費試用路線導航範例。請參閱 Directions API 試用版。
|
3 |
建構要求 |
請參閱範例要求,並瞭解可提供的選項,例如交通方式、中途點和路線限制。請參閱路線範例。
|
4 |
瞭解回覆的基本概念 |
探索資料回應,準備在應用程式中使用路線資料。詳情請參閱「路線回應」。 |
5 |
將路線資料整合到自己的應用程式! |
您可以使用這項資料計算旅行距離和時間。
|
可用的用戶端程式庫
透過下列任一用戶端程式庫,以您選擇的語言呼叫這項 API:
Google 地圖服務適用的 Java、Python、Go 和 Node.js 用戶端都是社群支援的用戶端程式庫,並依據阿帕契 2.0 授權的條款提供開放原始碼。您可以從 GitHub 下載這些用戶端,並查看安裝操作說明和程式碼範例。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThe Directions API provides route information between locations using various transportation modes like driving, walking, transit, or bicycling.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize your requests by specifying origins, destinations, waypoints, and travel preferences.\u003c/p\u003e\n"],["\u003cp\u003eThe API calculates the most efficient routes based on travel time, distance, and the number of turns.\u003c/p\u003e\n"],["\u003cp\u003eResults are available in JSON or XML format and include detailed directions, routes, legs, and steps.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries are available in Java, Python, Go, and Node.js for easy integration into your applications.\u003c/p\u003e\n"]]],[],null,["# Directions API (Legacy) 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\nThe Directions API (Legacy) is a service that accepts an HTTP request and returns JSON or XML-formatted directions between locations.\n\nWhy use the Directions API\n--------------------------\n\nWith the Directions API, you can get directions for several modes of\ntransportation, such as transit, driving, walking, or bicycling.\n\nWhat you can do with the Directions API?\n----------------------------------------\n\nWith the Directions API, you can calculate directions between locations,\nincluding the following details:\n\n- Directions for several modes of transportation, including transit, driving, walking or bicycling.\n- Multipart directions using a series of waypoints.\n- Specify origins, destinations, and waypoints in multiple ways, including as text strings (for example, \"Chicago, IL\" or \"Darwin, NT, Australia\"), place IDs, or latitude/longitude coordinates.\n\nHow the Directions API works\n----------------------------\n\nThe Directions API returns the most efficient routes when\ncalculating directions. The product factors in the following travel elements\nwhen determining the most efficient route:\n\n- Travel time (primary)\n- Distance\n- Number of turns\n\nThe following example request returns driving directions from Toronto, Ontario to Montreal, Quebec in JSON format: \n\n```scdoc\nhttps://maps.googleapis.com/maps/api/directions/json\n ?destination=Montreal\n &origin=Toronto\n &key=YOUR_API_KEY\n```\n\n### Resources\n\nThe following table summarizes the resources available through the\nDirections API along with the data it returns.\n\n\u003cbr /\u003e\n\n| Data resources | Data returned | Return format |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|\n| [Directions](/maps/documentation/directions/get-directions#DirectionsRequests) Supply origins and destinations in the form of place IDs, addresses, or latitude/longitude coordinates. See [required parameters](/maps/documentation/directions/get-directions#required-parameters) for details. | Detailed directions, broken into routes, legs, and steps. See [Directions responses](/maps/documentation/directions/get-directions#DirectionsResponses) for details. | - JSON - XML |\n\n\u003cbr /\u003e\n\nHow to use the Directions API\n-----------------------------\n\n|---|---------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 1 | **Get set up.** | Start with [Set up your Google Cloud project](/maps/documentation/directions/cloud-setup) and complete the setup instructions that follow. |\n| 2 | **Try the demo** | Once you have an API key and a cloud project you try out the directions demo at no charge. See [The Directions API demo](/maps/documentation/directions/start). |\n| 3 | **Build a request** | See the example requests and learn about the available options you can supply, such as travel modes, waypoints, and route restrictions. See [Directions examples](/maps/documentation/directions/get-directions#ExampleRequests). |\n| 4 | **Understand response basics** | Explore the data responses to prepare to use directions data for your app. See [Directions responses](/maps/documentation/directions/get-directions#DirectionsResponses) for details. |\n| 5 | **Incorporate direction data into your own app!** | You can use this data to calculate travel distance and time. |\n\n#### Available client libraries\n\nCall this API in the language of\nyour choice through one of the following client libraries:\n\n- [Java\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-java)\n- [Python\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-python)\n- [Go Client\n for Google Maps Services](https://github.com/googlemaps/google-maps-services-go)\n- [Node.js\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-js)\n\nThe Java Client, Python Client, Go Client and Node.js Client for Google Maps\nServices are community-supported client libraries, open sourced under the\n[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).\nDownload them from GitHub, where you can also find installation instructions and sample code.\n\nWhat's next\n-----------\n\n- **Start using the Directions API** : Go to [Get started](/maps/documentation/directions/start).\n- **Start making Directions requests** : Go to [Get\n directions](/maps/documentation/directions/get-directions).\n- **Follow best practices** : Go to [Web service best\n practices](/maps/documentation/directions/web-service-best-practices)."]]