0

我有以下代码

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

此代码在 Google 地图上制作 10 个标记,现在我想删除标记,以下是删除标记的代码。

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

此代码不起作用,它仅从标记中删除信息窗口,但不删除图像。请指导我做错了什么。

4

1 回答 1

1

您将标记推送到您注册的 GEvent 侦听器的回调函数内的 marker_list 数组中。您的数组将仅填充触发了其 InfoWindow 的标记。

移动“marker_list.push(marker);” 到“map.addoverlay(marker);”上方的行 IE..

  GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml("iLocator <b>"+Myarr[2]+"</b>");
                 });
                    marker_list.push(marker);
                    map.addOverlay(marker);
                }//End for
于 2011-04-15T04:42:17.943 回答