दूरी का मैट्रिक्स एपीआई शुरू करने का तरीका

सैंपल अनुरोध और उसका जवाब

यह उदाहरण, 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

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'

इसे आज़माएं! अपने वेब ब्राउज़र में यूआरएल डालकर इस अनुरोध की जांच करें - YOUR_API_KEY को अपनी असली एपीआई कुंजी से बदलना न भूलें. रिस्पॉन्स, दिए गए ऑरिजिन और डेस्टिनेशन के बीच की दूरी और कुल समय दिखाता है.

सभी उपलब्ध पैरामीटर के साथ-साथ, अनुरोध यूआरएल बनाने का तरीका जानें.

यह कोड सैंपल, JSON और एक्सएमएल फ़ॉर्मैट में है:

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>

जवाब को समझने के लिए डेवलपर की गाइड देखें.