I am trying to load a Heatmaps layer onto my google maps, but for some reason I just keep getting the error “Cannot read property ‘HeatmapLayer’ of undefined.”
JavaScript
x
21
21
1
map = new google.maps.Map(document.getElementById("gmaps"),{
2
zoom: 11,
3
center: new google.maps.LatLng(39.788403, -86.19990800000001),
4
mapTypeControl: false,
5
streetViewControl: false,
6
mapTypeId: google.maps.MapTypeId.ROADMAP,
7
panControl: false
8
});
9
10
heatMapData = [
11
new google.maps.LatLng(39.77745056152344, -86.10900878906250),
12
new google.maps.LatLng(39.82060623168945, -86.17008972167969),
13
new google.maps.LatLng(39.77947616577148, -86.17008972167969),
14
new google.maps.LatLng(39.82987594604492, -86.13955688476562),
15
new google.maps.LatLng(39.74195098876953, -86.12429046630860)
16
];
17
heatmap = new google.maps.visualization.HeatmapLayer({
18
data: heatMapData,
19
map: map
20
});
21
Here is the jsFiddle: http://jsfiddle.net/9HQ2a/3/
Advertisement
Answer
Add the visualization library to the URL when loading the google maps js.
JavaScript
1
2
1
<script async defer src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=visualization"></script>
2