I\'m using the HeatmapLayer api https://developers.google.com/maps/documentation/javascript/layers#JSHeatMaps
I generate the heatmap like this:
heatm
Using heatmap.setMap(null)
will only hide your heatmap layer.
If you later type heatmap.setMap(map)
, you will see your heatmap layer again, so it didn't really get deleted.
In order to delete the data you have to do the following steps.
heatmap.setMap(null)
//This will hide the heatmap layer
heatmap.getData().j = [];
//This is what actually sets the coordinates array to zero.
heatmap.setMap(map)
//Now when you toggle back the map, the heatlayer is gone and you can create a new one.
Hope this helps. Took me a while to figure it out, but it definitely worked.