Matt
Matt

Reputation: 1580

Removing KML overlay from Google Maps

I have a reset button that I want to reset the map (including removing overlays) when clicked.

I've been reading around and apparently the way you remove KML overlays is by;

  1. Declaring your kml variable as a global variable

    var ctaLayer = new google.maps.KmlLayer(null);

  2. These are the lines that cause the kml file to overlay on google maps

   var ctaLayer = new google.maps.KmlLayer(kmlFile);
   ctaLayer.setMap(map);
  1. And then call setMap(null) to remove the overlay.

    ctaLayer.setMap(null);

However, this does not seem to be working. I don't get any errors so I'm guessing I'm missing something? I'd appreciate any advice on getting this to work.

Upvotes: 3

Views: 8643

Answers (1)

geocodezip
geocodezip

Reputation: 161334

Remove the var from in front of the second var ctaLayer (the one that makes it local to the function).

Upvotes: 4

Related Questions