ผลิตภัณฑ์หรือฟีเจอร์นี้มีสถานะเป็นรุ่นเดิม ดูข้อมูลเพิ่มเติมเกี่ยวกับสถานะเดิมและวิธีย้ายข้อมูลจากบริการเดิมไปยังบริการใหม่กว่าได้ที่
ผลิตภัณฑ์และฟีเจอร์เดิม
ภาพรวมของ Directions API (เดิม)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
นักพัฒนาแอปในเขตเศรษฐกิจยุโรป (EEA)

Directions API (เดิม) เป็นบริการที่ยอมรับคำขอ HTTP และ
แสดงเส้นทางระหว่างสถานที่ในรูปแบบ JSON หรือ XML
เหตุผลที่ควรใช้ Directions API
Directions API ช่วยให้คุณขอเส้นทางสำหรับการเดินทางได้หลายรูปแบบ เช่น ขนส่งสาธารณะ การขับรถ การเดิน หรือการปั่นจักรยาน
คุณใช้ Directions API ทำอะไรได้บ้าง
Directions API ช่วยให้คุณคำนวณเส้นทางระหว่างสถานที่ต่างๆ ได้
รวมถึงรายละเอียดต่อไปนี้
- เส้นทางสำหรับโหมดการเดินทางหลายแบบ รวมถึงขนส่งสาธารณะ การขับรถ
การเดิน หรือการปั่นจักรยาน
- เส้นทางแบบหลายส่วนโดยใช้ชุดจุดอ้างอิง
- ระบุต้นทาง ปลายทาง และจุดแวะพักได้หลายวิธี เช่น สตริงข้อความ (เช่น "ชิคาโก รัฐอิลลินอยส์" หรือ "ดาร์วิน นอร์เทิร์นเทร์ริทอรี ออสเตรเลีย") รหัสสถานที่ หรือพิกัดละติจูด/ลองจิจูด
วิธีการทำงานของ Directions API
Directions API จะแสดงเส้นทางที่มีประสิทธิภาพมากที่สุดเมื่อ
คำนวณเส้นทาง ผลิตภัณฑ์จะพิจารณาองค์ประกอบการเดินทางต่อไปนี้
เมื่อกำหนดเส้นทางที่มีประสิทธิภาพที่สุด
- ระยะเวลาเดินทาง (หลัก)
- ระยะทาง
- จำนวนการเลี้ยว
คำขอตัวอย่างต่อไปนี้จะแสดงเส้นทางการขับขี่จากโทรอนโต รัฐออนแทรีโอ ไปยังมอนทรีออล รัฐควิเบก ในรูปแบบ JSON
https://maps.googleapis.com/maps/api/directions/json
?destination=Montreal
&origin=Toronto
&key=YOUR_API_KEY
แหล่งข้อมูล
ตารางต่อไปนี้สรุปทรัพยากรที่มีให้ผ่าน Directions API พร้อมกับข้อมูลที่ส่งคืน
แหล่งข้อมูล |
ข้อมูลที่แสดงผล |
รูปแบบการแสดงผล |
เส้นทาง
ระบุต้นทางและปลายทางในรูปแบบรหัสสถานที่ ที่อยู่
หรือพิกัดละติจูด/ลองจิจูด ดูรายละเอียดได้ที่พารามิเตอร์ที่จำเป็น
|
เส้นทางโดยละเอียดซึ่งแบ่งออกเป็นเส้นทาง ขา และขั้นตอน ดูรายละเอียดได้ที่
การตอบกลับเส้นทาง
|
|
วิธีใช้ Directions API
1 |
ตั้งค่า |
เริ่มต้นด้วยตั้งค่าโปรเจ็กต์ Google Cloud
และทําตามวิธีการตั้งค่า
ที่ตามมาให้เสร็จสมบูรณ์ |
2 |
ลองใช้เวอร์ชันเดโม |
เมื่อมีคีย์ API และโปรเจ็กต์ระบบคลาวด์แล้ว คุณจะลองใช้
การสาธิตเส้นทางได้โดยไม่มีค่าใช้จ่าย ดูการสาธิต Directions API
|
3 |
สร้างคำขอ |
ดูคำขอตัวอย่างและดูตัวเลือกที่มี
ซึ่งคุณระบุได้ เช่น โหมดการเดินทาง จุดแวะพัก และ
ข้อจำกัดของเส้นทาง ดูตัวอย่างเส้นทาง
|
4 |
ทำความเข้าใจพื้นฐานของคำตอบ |
สำรวจการตอบกลับของข้อมูลเพื่อเตรียมพร้อมใช้ข้อมูลเส้นทางสำหรับแอปของคุณ ดูรายละเอียดได้ที่�
การตอบกลับของเส้นทาง
|
5 |
รวมข้อมูลทิศทางลงในแอปของคุณเอง |
คุณใช้ข้อมูลนี้เพื่อคำนวณระยะทางและเวลาเดินทางได้
|
ไลบรารีของไคลเอ็นต์ที่พร้อมใช้งาน
เรียกใช้ API นี้ในภาษาที่คุณเลือกผ่านไลบรารีของไคลเอ็นต์ต่อไปนี้
ไคลเอ็นต์ Java, ไคลเอ็นต์ Python, ไคลเอ็นต์ Go และไคลเอ็นต์ Node.js สำหรับบริการ Google Maps เป็นไลบรารีของไคลเอ็นต์ที่ได้รับการสนับสนุนจากชุมชนและเป็นโอเพนซอร์สภายใต้สัญญาอนุญาต Apache 2.0
ดาวน์โหลดได้จาก GitHub ซึ่งคุณจะดูวิธีการติดตั้งและโค้ดตัวอย่างได้ด้วย
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\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)."]]