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