I\'m using the HeatmapLayer api https://developers.google.com/maps/documentation/javascript/layers#JSHeatMaps
I generate the heatmap like this:
heatm
The docs suggest you can remove a layer by calling heatmap.setMap(null)
Update
In your jsfiddle you were declaring your heatmap
variable in the scope of each click
event. To make your code work I moved the heatmap
variable to exist globally, and then checked to make sure that a new heatmap
did not overwrite an existing one.
Here is your updated jsfiddle