-1

我的脚本有问题,有人可以帮助我吗?

//Add event to google maps click => open marker.infobox
   for(var marker in markersWithArray){
       var lastInfoWindow; //Get lastInfoWindow for close google maps infowindow
       var markerI = markersWithArray[marker]; //Get marker from loop
       var infoWindow = markerI.infoWindow; //get infoWindow from marker, work prefectly
       console.log(infoWindow) // => all time good, object with
                               //    info box. All time unique id and content.

       google.maps.event.addListener(markerI, 'click', function() {
           console.log(infoWindow); //Problem here, object too, but id and content have 
                                    //a last value what recorded on top (console.log) 
                                    //last value of cycle
           if(lastInfoWindow)
               lastInfoWindow.close();
           infoWindow.open(map, this);
           lastInfoWindow = infoWindow;
       });
    }

谁能告诉我如何在事件“google.maps.event.addListener”中获得价值??谢谢 :)。

4

1 回答 1

1

如果您的标记有一个信息窗口作为属性(我不认为它是一个记录的属性,但您的问题暗示它存在),这应该有效:

   google.maps.event.addListener(markerI, 'click', function() {
       console.log(this.infoWindow);
       if(lastInfoWindow)
           lastInfoWindow.close();
       this.infoWindow.open(map, this);
       lastInfoWindow = this.infoWindow;
   });
于 2012-10-14T19:38:07.730 回答