On my map I own several Markers and each marker one infowindow, I have problems when adding more components to my infowindow where I have an Array and every one position information for each marker, see the code, the variable data that is the value of position of each array is not initialized in the addListener method.
function initialize() {
var latlng = new google.maps.LatLng(latitudes, longitudes);
var options = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("mapa"), options);
var pontos = [];
if (coord.length > 1) {
for (var i = 0; i < coord.length; i++) {
var location = coord[i].split(",");
var dados = veic[i]; // // Veic [] is an array that at each position, I have some information.
var marker = new google.maps.Marker({
position: new google.maps.LatLng(location[0], location[1]),
map: map
})
google.maps.event.addListener(marker, 'click', function () {
infoWindow.setContent("<b>Dados: </b>Carregando...");
infoWindow.open(map, this);
google.maps.event.addListener(infoWindow, 'domready', function () {
geocoder.geocode({ 'latLng': infoWindow.position }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
infoWindow.setContent("<b>Endereço: </b>" + results[0].formatted_address
+"</br> Veículo: "+ dados)} // Here in this passage, I can not get information from this variable.
});
});
});
}
}
}