Any simple way to clean all Markers, Polylines and other Overlays on Google Maps v3 API?

馋奶兔 提交于 2019-12-11 10:14:58

问题


I want to get a new map not using refush the webpage.

thanks

and has easy way to get all Overlays on the map?


回答1:


In the v2 API, there was the clearOverlays() method as Gaby pointed out. However, this method is not present if the v3 API. If I remember correctly, this omission was intentional to keep the library lightweight.

Therefore, with the v3 API, you have to keep a reference of your overlays, and then call setMap(null) on each overlay.




回答2:


Look the google map api documentation

And in particular: clearOverlays()




回答3:


FYI for peoples using V3: From what I have found, V3 does not have a packaged function like V2 does in .clearOverlays();

Here is what I do (as I've gathered from other resources):

var gmarkers = []; // establish your markers array;

if (gmarkers) { // plug this in wherever/whenever you want to clear the map of any and all markers;
    for (i in gmarkers) {
        gmarkers[i].setMap(null);
    }
    gmarkers.length = 0;
}


来源:https://stackoverflow.com/questions/3248373/any-simple-way-to-clean-all-markers-polylines-and-other-overlays-on-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!