function initialize() {
var latlng = new google.maps.LatLng(45, -85);
var coord = ["45,-85", "45.001,-85.01"];
var veic = ["some information", "other information"];
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 marker = new google.maps.Marker({
position: new google.maps.LatLng(location[0], location[1]),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
var dados = veic[i]; // // Veic [] is an array that at each position, I have some information.
infoWindow.setContent("<b>Dados: </b>Carregando...");
infoWindow.open(map, this);
google.maps.event.addListenerOnce(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.
});
});
};
})(marker, i));
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.