So, I'm parsing information and querying geocode with multiple addresses. I'm not entirely sure what's the best way of doing it. So here's what I'm trying to do.
for($j = 0; $j < $rawArray.length; $j++){
$baseStr = $addresNum != 'empty' ? $rawArray[$j][$addresNum] + ' ': '';
$baseStr += $addresStr != 'empty' ? $rawArray[$j][$addresStr] + ' ': '';
$baseStr += $addresDiv != 'empty' ? ', ' + $rawArray[$j][$addresDiv] : '';
$baseStr = ($baseStr.toLowerCase().indexOf("qc") >= 0 || $baseStr.toLowerCase().match(/qu[e-é]bec/) ? $baseStr : $baseStr + ", Qc");
console.log("Looking for: " + $baseStr.match(/\w\d\w([ ])*\d\w\d/i)[0]);
$baseStr = $baseStr.match(/\w\d\w([ ])*\d\w\d/i)[0];
$geocoder.geocode({
address: $baseStr
}, function(locResult, status) {
$arrayCoords[$j] = new Array();
if (status == google.maps.GeocoderStatus.OK) {
$arrayCoords[$j][0] = locResult[0].geometry.location.lat();
$arrayCoords[$j][1] = locResult[0].geometry.location.lng();
}else {
$arrayCoords[$j][0] = '';
$arrayCoords[$j][1] = '';
}
});
console.log("found: " + $arrayCoords[$j][0] + $arrayCoords[$j][1]);
}
Now, I figured that populating an array and working with it would be a good idea. So I did this:
$timeout = setInterval(function()
{
for($j = 0; $j < $rawArray.length; $j++){
console.log($globalGoogleArray[$j]);
}
if($globalGoogleArray.length == $rawArray.length)
{
console.log($globalGoogleArray);
//TODO: stopTimer();
}
}, 100);
And just before the console.log("found: " + $arrayCoords[$j][0] + $arrayCoords[$j][1]);
I added $globalGoogleArray[$j] = $arrayCoords[$j][0] + ", " + $arrayCoords[$j][1];
If I can get $globalGoogleArray populated with my values then I can stop the timer and trigger a function that will work with the content of the array. This may not be the the best way of doing it and I'm open to suggestions, still, I'm not ending with what I want. The timer is placed on top of the for and the console.log inside it only returns undefined, even tough the console.log in the for (this one: console.log("found: " + $arrayCoords[$j][0] + $arrayCoords[$j][1]);) does output what I expect it to output.
Can anyone enlighten me as to why I can't get the output of the geocode in my globalGoogleArray?