Using heatmap.setMap(null) will only hide your heat map layer. If you later type heatmap.setMap(map) , you will again see your heat map layer, so you really didn’t delete it.
To delete data, you need to do the following:
heatmap.setMap(null) // This will hide the heat map layer
heatmap.getData().j = []; // This is what actually sets the array of coordinates to zero.
heatmap.setMap(map) // Now, when you switch back the map, the heater does not work, and you can create a new one.
Hope this helps. Spent me figure it out, but it definitely worked.
source share