Erste Schritte mit der Distance Matrix API

Beispielanforderung und -antwort

In diesem Beispiel werden die Distance Matrix-Daten zwischen Washington, DC und New York City, NY, im JSON-Format angefordert:

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'

Testen! Testen Sie die Anfrage, indem Sie die URL in den Webbrowser eingeben. Ersetzen Sie dabei YOUR_API_KEY durch Ihren tatsächlichen API-Schlüssel. In der Antwort werden die Entfernung und die Reisezeit zwischen den angegebenen Start- und Zielorten angezeigt.

Anfrage-URLs erstellen (einschließlich aller verfügbaren Parameter)

Dieses Codebeispiel liegt im JSON- und im XML-Format vor:

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>

Im Entwicklerhandbuch finden Sie Informationen zur Antwort.