این محصول یا ویژگی در وضعیت Legacy است و برای استفاده جدید قابل فعال نیست. برای اطلاعات بیشتر در مورد مرحله Legacy و نحوه انتقال از Legacy به سرویسهای جدیدتر، به
محصولات و ویژگیهای Legacy مراجعه کنید.، این محصول یا ویژگی در وضعیت Legacy است و برای استفاده جدید نمیتوان آن را فعال کرد. برای اطلاعات بیشتر درباره مرحله Legacy و نحوه انتقال از Legacy به سرویسهای جدیدتر، به
محصولات و ویژگیهای Legacy مراجعه کنید.
با Distance Matrix API شروع کنید
نمونه درخواست و پاسخ
این مثال داده های ماتریس فاصله بین واشنگتن، دی سی و شهر نیویورک، نیویورک را در قالب JSON درخواست می کند:
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 -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 می باشد:
{
"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",
}
<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Washington, DC, USA</origin_address>
<destination_address>New York, NY, USA</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>14078</value>
<text>3 hours 55 mins</text>
</duration>
<distance>
<value>367654</value>
<text>228 mi</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>
برای درک پاسخ، راهنمای توسعهدهنده را بررسی کنید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-03-01 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-03-01 بهوقت ساعت هماهنگ جهانی."],[[["This page provides a sample request and response for the Distance Matrix API, demonstrating how to calculate the distance and travel time between two locations."],["The example uses Washington, DC and New York City, NY as locations and showcases the request URL, cURL command, and expected JSON/XML responses."],["Users are encouraged to try the example with their own API key and explore further documentation on building requests and understanding responses."]]],["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"]]