I'm facing an issue with the following code snippet:
function calculateDistance() {
var calcDirection = document.getElementById('street').value + "+" + document.getElementById('number').value + "+UK";
for (var x = 0; x < dbdirection.length; x++) {
var dirDest = dbdirection[x].replace(" ","+")+ "+UK";
$.getJSON("http://maps.googleapis.com/maps/api/distancematrix/json?origins="+calcDirection+"&destinations="+dirDest+"&mode=walking&language=es-ES&sensor=false", function(data) {
var distance = data.rows[0].elements[0].distance.value;
// return distance;
});
// alert(distance);
}
}
The challenge I'm encountering is retrieving the distance value from the getJSON
call. After researching, I came across suggestions to use "&callback="
at the end of the URL, but I couldn't make it work (possibly due to my lack of understanding on how to implement it). Any guidance on how to address this would be greatly appreciated.
Thank you in advance