我在地圖上有多個標記。但它不會將相應的infoWindows附加到標記。他們總是在左上角。不知道這裏干擾什麼。Google地圖標記錯誤位置
var geocoder = new google.maps.Geocoder();
var addresses = [
'Marienstr. 37a 27472 Cuxhaven',
'Bahnhofstr. 15 21745 Hemmoor',
'Richtpfad 20 26506 Norden',
'Eulenbusch 4 21391 Reppenstedt'
];
var bounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow(), marker, i;
for (i=0; i < addresses.length; i++) {
geocoder.geocode({ 'address': addresses[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// map.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(addresses[i]);
infowindow.open(map, marker);
};
})(marker, i));
bounds.extend(results[0].geometry.location);
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}