Hi I'm calling this function:
function getCoordenadas()
{
var coordenadas = new Array();
$.post(
'<?=$this->baseUrl('user/parse-kml')?>',
{ kmlName: "esta_chica.kml"},
function(jsonCoord) {
jQuery.each(jsonCoord, function(i, val) {
var latlng = val.split(',');
coordenadas.push(new google.maps.LatLng(latlng[0], latlng[1]));
});
},
'json'
);
return coordenadas;
}
like this:
$(document).ready(function(){
$('.caller').click(function() {
console.log(getCoordenadas());
});
});
So when you click .caller it calls the function gets the data correctly populates the array, but console.log(getCoordenadas()); outputs [].
If I move the array declaration (var coordenadas = new Array();) from the function scope to make it global, when I click .caller for the first time console.log(getCoordenadas()); outputs [], but the second time it outputs the array correctly. Any ideas?
Thanks in advance