I have viewed a lot of other questions relating to this, but found no direct answer.
Similar to all other problems, I have 4 elements in the array, however array.length returns 0. Below is my code:
for (count = 0; count < noPax; count++) {
var latStr = "lat" + count;
var longStr = "long" + count;
// var latitude = document.getElementById(latStr).value;
var geocoder = new google.maps.Geocoder();
var address = document.getElementById(latStr).value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
locations.push(latitude);
locations.push(longitude);
} else {
alert("Geocode was not successful for the following reason: " + status);
window.location.reload();
}
});
// var longitude = document.getElementById(longStr).value;
}
var bound = new google.maps.LatLngBounds();
console.log(locations);
console.log(locations.length);
for (i = 0; i < locations.length; i += 2) {
bound.extend( new google.maps.LatLng(locations[i], locations[i+1]) );
}
Here is the console log:
Appreciate the help!