Simply do the following:(只需执行以下操作:)
I. Declare a global variable:(I.声明一个全局变量:)
var markersArray = [];
II.(II。)
Define a function:(定义一个函数:)
function clearOverlays() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
OR(要么)
google.maps.Map.prototype.clearOverlays = function() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
III.(III。)
Push markers in the 'markerArray' before calling the following:(在调用以下内容之前在'markerArray'中推送标记:)
markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});
IV.(IV。)
Call the clearOverlays();
(调用clearOverlays();
) or map.clearOverlays();
(或map.clearOverlays();
) function wherever required.(在任何需要的地方运作)
That's it!!(而已!!)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…