2
votes

Trying out the Google Maps Distance Matrix API for calculating the time between the origin and destination and I'm using this API

https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=32.988777,xxxx&destinations=32.988777,xxxx&key=myAPIKey (xxxx - I'm providing a valid value just masking it on here)

I am getting a response as

{
   "destination_addresses" : [ "Plano, TX 75024, USA" ],
   "origin_addresses" : [ "Coppell, TX 75019, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "13.4 mi",
                  "value" : 21636
               },
               "duration" : {
                  "text" : "14 mins",
                  "value" : 833
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

But I'm unable to correlate the req and response as the response is missing the long/lat, How do I solve this issue?

1

1 Answers

1
votes

Per official documentation: DistanceMatrix service does not include lat/lng element in response. See all available elements here: https://developers.google.com/maps/documentation/distance-matrix/intro#DistanceMatrixResponses

Nonetheless, looking at your request, it appears that you already supplied lat/lng in your input. On the other hand if you supplied address as origins/destinations and aiming to extract the corresponding coordinates, then you can simply do forward Geocode afterwards.