Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that there is no such function in V3 yet.</p> <p>People suggest to keep references to all markers you have on the map in an array. And then when you want to delete em all, just loop trough the array and call .setMap(null) method on each of the references.</p> <p><a href="https://stackoverflow.com/questions/953394/is-it-ok-clearoverlays-in-gmap-api-v2-to-google-maps-api-v3">See this question for more info/code.</a></p> <p>My version:</p> <pre><code>google.maps.Map.prototype.markers = new Array(); google.maps.Map.prototype.getMarkers = function() { return this.markers }; google.maps.Map.prototype.clearMarkers = function() { for(var i=0; i&lt;this.markers.length; i++){ this.markers[i].setMap(null); } this.markers = new Array(); }; google.maps.Marker.prototype._setMap = google.maps.Marker.prototype.setMap; google.maps.Marker.prototype.setMap = function(map) { if (map) { map.markers[map.markers.length] = this; } this._setMap(map); } </code></pre> <p><em>The code is edited version of this code <a href="http://www.lootogo.com/googlemapsapi3/markerPlugin.html" rel="noreferrer">http://www.lootogo.com/googlemapsapi3/markerPlugin.html</a> I removed the need to call addMarker manually.</em></p> <p>Pros</p> <ul> <li>Doing this way you keep the code compact and in one place (doesn't pollute the namespace).</li> <li>You don't have to keep track of the markers yourself anymore you can always find all the markers on the map by calling map.getMarkers()</li> </ul> <p>Cons</p> <ul> <li>Using prototypes and wrappers like I did now makes my code dependent on Google code, if they make a mayor change in their source this will break.</li> <li>If you don't understand it then you won't be able to fix it if does break. The chances are low that they're going to change anything which will break this, but still..</li> <li>If you remove one marker manually, it's reference will still be in markers array. (You could edit my setMap method to fix it, but at the cost of looping trough markers array and removing the reference) </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload