I implemented something similar for my final year university project. I used the same approach as HeatMap API, overlaying a generated image on the map when it is repositioned.
I wrote a custom Java web server accepting the bounding box co-ordinates in the querystring to produce a semi-transparent PNG image that looked somewhat like a heat-map, but it was by no means a proper statistically correct algorithm. At the time I wasn't able to find any algorithms for creating the heatmap and many of the algorithms found online or in journals were actually for cluster heat-maps/tree-maps rather than density heatmaps.
I generated a 2D array for the data, using a function to map each co-ordinate with a value. Adding to the array increased the values, so the array needed to be normalised to a value between 0-255, which can then be easily colored and output onto a canvas. I'm afraid I can't find the source code for this, and the algorithm was very approximate.
A year or so ago when the members list of the BNP (racist British political party) was leaked I came across another (simpler, but probably even less accurate) solution that placed a PNG heat spot at each pin point, creating the effect of a heat-map. There is a screenshot of this here, although I can't find the original map http://www.labourlist.org/revealed%5Fthe%5Fbnps%5Fsocial%5Fmedia%5Fstrategy%5Fmark%5Fhanson