Sunny
Sunny

Reputation: 10105

Clarification required on Google Maps DistanceMatrixResponse

I am reading on Google Maps Distance Matrix Responses and am unable to understand how the response can have four distances when there are only two source-destination pairs. The following is from the documentation. I have use the API before but not this particular service. Please clarify. May be I am missing something basic here.

 {
      "origin_addresses": [ "Greenwich, Greater London, UK", "13 Great Carleton Square, Edinburgh, City of Edinburgh EH16 4, UK" ],
      "destination_addresses": [ "Stockholm County, Sweden", "Dlouhá 609/2, 110 00 Praha-Staré Město, Česká republika" ],
      "rows": [ {
        "elements": [ {
          "status": "OK",
          "duration": {
            "value": 70778,
            "text": "19 hours 40 mins"
          },
          "distance": {
            "value": 1887508,
            "text": "1173 mi"
          }
        }, {
          "status": "OK",
          "duration": {
            "value": 44476,
            "text": "12 hours 21 mins"
          },
          "distance": {
            "value": 1262780,
            "text": "785 mi"
          }
        } ]
      }, {
        "elements": [ {
          "status": "OK",
          "duration": {
            "value": 96000,
            "text": "1 day 3 hours"
          },
          "distance": {
            "value": 2566737,
            "text": "1595 mi"
          }
        }, {
          "status": "OK",
          "duration": {
            "value": 69698,
            "text": "19 hours 22 mins"
          },
          "distance": {
            "value": 1942009,
            "text": "1207 mi"
          }
        } ]
      } ]

The documentation states, and I quote:

The supported fields in a response are explained below.

originAddresses is an array containing the locations passed in the origins field of the Distance Matrix request. The addresses are returned as they are formatted by the geocoder. destinationAddresses is an array containing the locations passed in the destinations field, in the format returned by the geocoder.

rows is an array of DistanceMatrixResponseRow objects, with each row corresponding to an origin.

elements are children of rows, and correspond to a pairing of the row's origin with each destination. They contain status, distance, and duration information for each origin/destination pair.

The distance, duration and duration_in_traffic fields for each element include both a value (which is always shown in meters or seconds), and a text field, which supplies a more human-readable version of the information. The distance's text value is formatted according to the unitSystem specified in the request (or in metric, if no preference was supplied).

Upvotes: 0

Views: 217

Answers (1)

ChrisSwires
ChrisSwires

Reputation: 2723

The example you've given above shows two origins and two destinations, they are not paired. Each row response corresponds to an origin point, with each element being a route from that origin to a destination.

In the example above it is returning the distance from Greenwich to Stockholm County and the Czech Republic and then the distance from Edinburgh to Stockholm County and the Czech Republic. So the distances from point A to C and D, and then point B to C and D.

Does that clarify things a little?

Upvotes: 2

Related Questions