2013-09-26 51 views
1

我试试这个,但是我只能保存windowInfo。 请帮助我Show One WindowInfo Per Marker(Google Map)

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); 
+0

改进问题的格式。 –

回答

1

变化的开放)的第二个参数(以this

infowindow.open(map,this); 

variable标记,这将在每次迭代被覆盖。循环完成后,它指向已创建的最后一个标记。 thisclick -callback指已被点击的标记。