I need to create an array from Google Maps JSON data, within a JQuery each function.
To that effect I have:
var markerlocations = new Array();
$(function() {
$(".markerloc").each(function( index ) {
var addressval = $(this).val();
var jsonLtdLng="https://maps.googleapis.com/maps/api/geocode/json?address=" + addressval;
$.getJSON(jsonLtdLng, function (data) {
var lat = data.results[0].geometry.location.lng;
var lng = data.results[0].geometry.location.lng;
var latlng = "{lat: " + lat + ", lng: " + lng + "}";
markerlocations.push(latlng);
console.log(latlng);
});//END JSON
});//END EACH
console.log(markerlocations);
});//END PAGE READY
console.log(latlng);
produces the expected result, but this does not seem to be pushed to the markerlocations
array - the console just shows it as empty.
Would anyone know what's going on here and be able to point me in the right direction?