2

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

thanks

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

Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
zjm1126
  • 63,397
  • 81
  • 173
  • 221

3 Answers3

3

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.

Community
  • 1
  • 1
Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
1

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;
}
Marc
  • 233
  • 1
  • 2
  • 5
0

Look the google map api documentation

And in particular: clearOverlays()

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317