您还需要在地理编码器调用上使用函数闭包(未测试),看起来您的listMarker函数也可能有问题(似乎缺少“info”的定义,如果您依赖于它的全局值,那可能是您的问题):
function geocodeAddress(msg)
{
geocoder.geocode( { 'address': msg}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
animation: google.maps.Animation.DROP,
icon: image,
position: results[0].geometry.location
})
listenMarker(marker, msg);
markerBounds.extend(results[0].geometry.location);
map.fitBounds(markerBounds);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
for (var i = 0; i < msg.length; i++) {
info = msg[i];
console.log(info);
geocodeAddress(msg[i]);
}
function listenMarker (marker, info){
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(info);
infoWindow.open(map, this);
});