1

我试试这个,但我只能坚持 windowInfo。请帮帮我

function initialize() {
var mapOptions = {
    zoom: 5,
    center: new google.maps.LatLng(33.414837,54.68141),
    mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
/*var weatherLayer = new google.maps.weather.WeatherLayer({
    temperatureUnits: google.maps.weather.TemperatureUnit.Degree
});
weatherLayer.setMap(map);*/
/*var cloudLayer = new google.maps.weather.CloudLayer();
cloudLayer.setMap(map)*/
for (i = 0; i < StationListArray.length; i++) {
    var image = StationListArray[i].split("|")[4];
    var StationLocation = new google.maps.LatLng(StationListArray[i].split("|")[2], StationListArray[i].split("|")[1]);
    var marker = new google.maps.Marker({
        position: StationLocation,
        map: map,
        title: StationListArray[i].split("|")[0],
        icon: image
    });
    google.maps.event.addListener(marker,'click',function() {
    var infowindow = new google.maps.InfoWindow({
    content:"Hello World!"});
    infowindow.open(map,marker); 
    });

} 
}
google.maps.event.addDomListener(window, 'load', initialize);
4

1 回答 1

1

将 open() 的第二个参数更改为this

infowindow.open(map,this);

marker指的是variable标记,它将在每次迭代时被覆盖。循环完成后,它指向已创建的最后一个标记。this-callback内部是click指已单击的标记。

于 2013-09-26T12:40:18.847 回答