Heatmap Layer

Overview

A heatmap is a visualization used to depict the intensity of data at
geographical points. When the Heatmap Layer is enabled, a colored overlay will
appear on top of the map. By default, areas of higher intensity will be colored
red, and areas of lower intensity will appear green.

The Maps JavaScript API can either render heatmap data client-side via
the Heatmap Layer, or server-side via a Fusion
Table. Some of the key
differences between the two methods include:

Heatmap Layer

Fusion Table Layer

A large number of data points may result in reduced performance.

More data points will have little impact on performance.

Able to customize the appearance of the heatmap by changing such
options as: the color gradient, the radius of data points, and the
intensity of each data point.

No ability to customize the appearance of the heatmap.

Able to control whether heatmap data dissipates at higher zoom levels
or not.

All heatmap data will dissipate as you zoom in.

Data can be stored with your HTML, stored on a server, or calculated
on the fly. Data can be changed at runtime.

All data must be stored in a Fusion Table. Data cannot be easily
changed at runtime.

Load the visualization library

The Heatmap Layer is part of the google.maps.visualization library, and is not
loaded by default. The Visualization classes are a self-contained library,
separate from the main Maps JavaScript API code. To use the functionality
contained within this library, you must first load it using the libraries
parameter in the Maps JavaScript API bootstrap URL:

Add a Heatmap Layer

To add a Heatmap Layer, you must first create a new HeatmapLayer
object, and provide it with some geographic data in the form of an array or an
MVCArray[] object. The data may be either a
LatLng
object or a
WeightedLocation
object. After instantiating the HeatmapLayer object, add it to the
map by calling the setMap() method.

Add Weighted Data Points

A heatmap can render either
LatLng or
WeightedLocation
objects, or a combination of the two. Both objects represent a single data
point on a map, but a WeightedLocation object allows you to additionally
specify a weight for that data point. Applying a weight to a data point will
cause the WeightedLocation to be rendered with a greater intensity than a
simple LatLng object. The weight is a linear scale, in which each LatLng
object has an implicit weight of 1 — adding a single WeightedLocation
of {location: new google.maps.LatLng(37.782, -122.441), weight: 3} will have
the same effect as adding google.maps.LatLng(37.782, -122.441) three times.
You can mix weightedLocation and LatLng objects in a single array.

Using a WeightedLocation object in place of a LatLng can be useful when:

Adding large amounts of data at a single location. Rendering a single
WeightedLocation object with a weight of 1000 will be faster than
rendering 1000 LatLng objects.

Applying an emphasis to your data based upon arbitrary values. For example,
you can use LatLng objects when plotting earthquake data, but you may want
to use a WeightedLocation to measure the magnitude of each earthquake on
the richter scale.

Customize a Heatmap Layer

You can customize how your heatmap will be rendered with the following heatmap
options. See the
HeatmapLayerOptions documentation for more information.

dissipating: Specifies whether heatmaps dissipate on zoom. When
dissipating is false the radius of influence increases with zoom level to
ensure that the color intensity is preserved at any given geographic
location. Defaults to true.

gradient: The color gradient of the heatmap, specified as an array of CSS
color strings. All CSS3 colors
— including RGBA — are supported except for extended named
colors and HSL(A) values.

maxIntensity: The maximum intensity of the heatmap. By default, heatmap
colors are dynamically scaled according to the greatest concentration of
points at any particular pixel on the map. This property allows you to
specify a fixed maximum. Setting the maximum intensity can be helpful when
your dataset contains a few outliers with an unusually high intensity.

radius: The radius of influence for each data point, in pixels.

opacity: The opacity of the heatmap, expressed as a number between 0 and 1.