I'm working with a piece of code from Google, trying to alter it such that instead of windows.alerting the LT/LN coordinates, the coordinates get saved in an Array that can then be displayed in a table of some kind.
function geocodeAddress(geocoder, resultsMap) {
var cords = []; //my array
var address = document.getElementById('address').value;
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
window.alert("Coordinates:" + results[0].geometry.location); //current alert
cords.push(results[0].geometry.location); //adding to an Array
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
I'm very rusty with JS, so i'm not even sure if it is being stored in Array. I tried a number of ways to display the Array to the screen but nothing worked, i'm not sure if that is because nothing is being stored in the array or because i'm not display the array correctly.
Explicitly put: Any ideas on how to store these coordinates in array & how should I go about display this array on screen? Cheers.
console.log(cords)and open developer tools (f12) to see the output, but it looks fine. As for adding them to html there are a legend of possible solutions; here is a vanilla JS implementation : stackoverflow.com/questions/5886144/…