0

我正在使用谷歌地图 javascript api,标记侦听器。当我点击标记信息窗口应该弹出。在 for 循环中,我添加了多个(在本例中为 3 个)标记。这是代码:

       for (z = 0; z < 3; z++) {
            arrMarkers.push( new google.maps.Marker({
            position: flightPlanCoordinates[arrCoords.length-1],
            map: map, title: 'Kraj', clickable: true
            }));        

            arrInfoWindow.push( new google.maps.InfoWindow({
                content: 'Hello world'
            }));

            google.maps.event.addListener(arrMarkers[z], 'click', function() {
                    arrInfoWindow[z].open(map, arrMarkers[z]);
            });
       }

信息窗口不弹出。

4

1 回答 1

0

你不能在 arrInfoWindow 上推送信息窗口,它需要分开
试试这个

for (z = 0; z < 3; z++) 
{
  arrMarkers.push( new google.maps.Marker({
  position: flightPlanCoordinates[arrCoords.length-1],
  map: map, title: 'Kraj', clickable: true
  }));        

  var infoWindow = new google.maps.InfoWindow({
      content: 'Hello world'
  });
  arrInfoWindow.push( infoWindow );

  google.maps.event.addListener(arrMarkers[z], 'click', function() {
          arrInfoWindow[z].open(map, arrMarkers[z]);
  });
}
于 2012-11-05T10:33:38.897 回答