我对谷歌地图有问题 V3 代码是谷歌示例的一部分。我想将侦听器添加到每个标记,所以我将标记设置为数组。但它不起作用:(有人可以帮助我吗?
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
// Add 10 markers to the map at random locations
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var marker = new Array(10);
for (var i = 0; i < 10; i++) {
var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
southWest.lng() + lngSpan * Math.random());
marker[i] = new GMarker(latlng,{ draggable: true });
GEvent.addListener(marker[i] , "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker[i] , "dragend", function() {
marker[i].openInfoWindowHtml("text" + i);
});
map.addOverlay(marker[i] );
}
}
}