First of all, I'm trying to create Heatmaps using google.maps.visualization.HeatmapLayer.
I'm trying to call the function codeAddress n times, and every time I call It, It's supposed to create a new google.maps.LatLng object in the global array locationsList , but when I try to return locationsList on the function getPoints it is empty.
Any idea why?
var locationsList = [];
var counter = 0;
    function getPoints(latitude, longitude) {   
            codeAddress(" APIAI, SP, Brasil",2271.96);
            codeAddress(" Avaré, SP, Brasil",8.77);
            codeAddress(" Barueri, SP, Brasil",263.1);
            codeAddress(" Caçapava, SP, Brasil",2130.24);
            codeAddress(" Cajati, SP, Brasil",157.26);
            codeAddress(" Campinas, SP, Brasil",83.28);
            codeAddress(" CARAGUATATUBA, SP, Brasil",325.08);
        console.log("All codeaddress ended "+locationsList.length); // prints 0 (array disappears?)
          return locationsList;
        }
function codeAddress(endereco, peso) {   
    geocoder.geocode( { 'address': endereco}, function(results, status) {
      if (status == 'OK') {                     
    var thislat = results[0].geometry.location.lat();
    var thislong = results[0].geometry.location.lng();
        locationsList[this.contador] = {location: new google.maps.LatLng(thislat,thislong), weight: peso};
        console.log(locationsList.length);
        contador++;
                 } else {
        alert('Geocode was not successful for the following reason: ' + status);
      }
    });
  } 
 
    