בקשה ותשובה לדוגמה
בדוגמה הזו מבקשים את נתוני מטריצת המרחק בין וושינגטון הבירה לניו יורק, ניו יורק, בפורמט 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
<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>
כדי להבין את התשובה, אפשר לעיין במדריך למפתחים.