I am trying to fetch the real-time duration of a particular route on Google Maps through my JavaScript code. However, I seem to be stuck. Here's what I have written so far:
$(document).ready(function Duration() {
var d = new Date();
$.ajax({
url: 'http://maps.googleapis.com/maps/api/distancematrix/json?origins=91058%20Haupt%20Str.%6+DE&destinations=91058%20Cauerstr.%208+DE&mode=driving&language=de-DE&sensor=false&traffic_model=best_guess&departure_time='+(d.getTime()+300000),
dataType: "json"
}).done(function(data) {
var dur = data.rows[0].elements[0].duration.text;
$("#duration").text(dur);
});
});
Simply want to display in HTML using:
<div id="duration"></div>
Would appreciate some assistance! Thank you in advance :)