ผลิตภัณฑ์หรือฟีเจอร์นี้อยู่ในสถานะเดิม ดูข้อมูลเพิ่มเติมเกี่ยวกับระยะเดิมและวิธีย้ายข้อมูลจากบริการเดิมไปยังบริการที่ใหม่กว่าได้ที่
ผลิตภัณฑ์และฟีเจอร์เดิม
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
เริ่มต้นใช้งาน Distance Matrix API (เดิม)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัวอย่างคำขอและการตอบกลับ
ตัวอย่างนี้จะขอข้อมูลเมทริกซ์ระยะทางระหว่างวอชิงตัน ดี.ซี. กับ
นิวยอร์กซิตี้ รัฐนิวยอร์ก ในรูปแบบ JSON
URL
https://maps.googleapis.com/maps/api/distancematrix/json
?destinations=New%20York%20City%2C%20NY
&origins=Washington%2C%20DC
&units=imperial
&key=YOUR_API_KEY
curl
curl -L -X GET 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY'
ลองใช้งาน ทดสอบคำขอนี้โดยป้อน URL ลงในเว็บเบราว์เซอร์ อย่าลืมแทนที่ YOUR_API_KEY ด้วยคีย์ API จริงของคุณ การตอบกลับจะแสดงระยะทางและระยะเวลาระหว่างต้นทางและปลายทางที่ระบุ
ดูวิธีสร้าง URL คำขอ
รวมถึงพารามิเตอร์ที่มีอยู่ทั้งหมด
ตัวอย่างโค้ดนี้อยู่ในรูปแบบ JSON และ XML
JSON
{
"destination_addresses": ["New York, NY, USA"],
"origin_addresses": ["Washington, DC, USA"],
"rows":
[
{
"elements":
[
{
"distance": { "text": "228 mi", "value": 367654 },
"duration": { "text": "3 hours 55 mins", "value": 14078 },
"status": "OK",
},
],
},
],
"status": "OK",
}
XML
OK
Washington, DC, USA
New York, NY, USA
OK
14078
3 hours 55 mins
367654
228 mi
โปรดอ่านคู่มือนักพัฒนาแอปเพื่อทำความเข้าใจการตอบกลับ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2026-04-29 UTC
[null,null,["อัปเดตล่าสุด 2026-04-29 UTC"],[],["The content demonstrates requesting distance data between Washington, DC, and New York City using the Google Maps Distance Matrix API. The request URL and cURL command are provided, requiring the user to replace `YOUR_API_KEY` with their own. The API returns distance (228 mi) and duration (3 hours 55 mins) data in both JSON and XML formats. Users can test the URL and further understand responses, and can learn to build custom URL requests through provided documentation.\n"]]