2011-04-15 156 views
0

我有以下代码谷歌地图API V2标记问题

var marker; 
var marker_list = []; 
        for (iLoopIndex=0;iLoopIndex<10;iLoopIndex++) 
        { 
         centerPoint = new GLatLng(32+iLoopIndex,68+iLoopIndex); 
         alert(centerPoint); 
         map.setCenter(centerPoint); 

         blueIcon = new GIcon(G_DEFAULT_ICON); 
         blueIcon.image = "truck.png"; 
         blueIcon.iconSize = new GSize(40, 20); 

         // Set up our GMarkerOptions object 
         markerOptions = { icon:blueIcon }; 
         //map.addOverlay(new GMarker(centerPoint, markerOptions)); 
         marker = new GMarker(centerPoint, markerOptions); 

         GEvent.addListener(marker, "click", function() { 
         marker.openInfoWindowHtml("iLocator <b>"+Myarr[2]+"</b>"); 
         marker_list.push(marker); 
        }); 
         map.addOverlay(marker); 
        }//End for 

本准则就谷歌地图10个标记,现在我想删除标记,以下是删除标记的代码。

for (iLoopIndex=0;iLoopIndex<marker_list.length;iLoopIndex++) 
{ 
    map.removeOverlay(marker_list[iLoopIndex]); 
} 

此代码不工作,它只能从标记中删除infowindow,但不会删除图像。请引导我做错了什么。

+1

现在是时候升级到GoogleMaps v3,因为它完全从v2更改。大多数开发人员可能无法帮助您。 removeOverlay调用后,可能需要使用Firebug for map对象进行调试。 – Senthil 2011-04-15 04:41:35

回答

1

您正在将您的标记插入您注册的GEvent Listener的回调函数内的marker_list数组中。您的数组只会填充其InfoWindow触发的标记。

移动“marker_list.push(marker);”到上面的“map.addoverlay(marker);”即..

GEvent.addListener(marker, "click", function() { 
        marker.openInfoWindowHtml("iLocator <b>"+Myarr[2]+"</b>"); 
       }); 
        marker_list.push(marker); 
        map.addOverlay(marker); 
       }//End for 
+0

还有一个问题是我面对的信息窗口只显示在一个标记上。 – Siddiqui 2011-04-15 07:16:20