Google Maps V3: Only show markers in viewport - Clear markers issue

前端 未结 6 1206
再見小時候
再見小時候 2021-01-30 04:33

I like to create a map with Google Maps that can handle large amounts of markers (over 10.000). To not slow down the map I\'ve created a XML-file that only outputs the markers t

6条回答
  •  遇见更好的自我
    2021-01-30 05:09

    You need to add another Event Listener to the map:

    google.maps.event.addListener(map,'bounds_changed', removeMarkers);
    

    See here for more on removing all markers from a google map - unfortunately I dont think it can be done with one call. So you will have to write the removeMarkers or something similar which will have to iterate through all the markers on the map removing them individually like so:

     markersArray[i].setMap(null);
    

    I don't know whether it's quicker to check if the marker is in the viewport before removing by using:

     map.getBounds();
    

    Read more about Google Map API v3 events

提交回复
热议问题