0
votes

I have something like this:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=Berlin&destinations=Frankfurt&mode=driving&language=de-DE&sensor=false

How to display "549 km and 5 Stunden, 21 Minuten" from this json output in my website?

1
I think we will need more information to help you. Are you accessing that URL on the server or on the client? What function, library, or other tool are you using to access it?Elias Zamaria
On the client. I would like use jQueryuser1745580

1 Answers

0
votes

Something like this:

var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
  {
    origins: ["Berlin"],
    destinations: ["Frankfurt"],
    travelMode: google.maps.TravelMode.DRIVING,
  }, callback);

function callback(response, status) {
  $("#result").text(response.rows[0].elements.distance.text + " and " + response.rows[0].elements.duration.text);
}

It looks fine to me but I haven't tested it so I may not be getting all the details right. I don't know how to get the result in German but this documentation may be helpful.

In place of $("#result"), you need a selector or collection for the element where you want to show the result.