Google map api V2 Marker Issue
I have the following code
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
This Code make 10 markers on Google map, now I want to remove the markers, following is the code to remove the markers.
for (iLoopIndex=0;iLoopIndex<marker_list.length;iLoopIndex++)
{
map.removeOverlay(marker_list[iLoopIndex]);
}
This code is not working its only remove the infowindow from the marker but not开发者_开发知识库 removing the image. Kindly guide me what I am doing wrong.
You're pushing your markers into your marker_list array inside the callback function for the GEvent Listener that you registered.. Your array will only be populated with Markers that had their InfoWindow triggered.
Move "marker_list.push(marker);" to the line above "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
精彩评论