javascript - Google Maps API v3 热图错误 : "Cannot read property ' HeatmapLayer' of undefined"

标签 javascript jquery google-maps google-maps-api-3 heatmap

我正在尝试将 Heatmaps 图层加载到我的谷歌地图上,但出于某种原因,我一直收到错误消息“无法读取未定义的属性‘HeatmapLayer’。”

map = new google.maps.Map(document.getElementById("gmaps"),{
    zoom: 11,
    center: new google.maps.LatLng(39.788403, -86.19990800000001),
    mapTypeControl: false,
    streetViewControl: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false
});

heatMapData = [
new google.maps.LatLng(39.77745056152344, -86.10900878906250),
new google.maps.LatLng(39.82060623168945, -86.17008972167969),
new google.maps.LatLng(39.77947616577148, -86.17008972167969),
new google.maps.LatLng(39.82987594604492, -86.13955688476562),
new google.maps.LatLng(39.74195098876953, -86.12429046630860)
];
heatmap = new google.maps.visualization.HeatmapLayer({
    data: heatMapData,
    map: map
});

这是 jsFiddle:http://jsfiddle.net/9HQ2a/3/

最佳答案

在加载 google maps js 时将可视化库添加到 URL

<script async defer src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=visualization"></script>

关于javascript - Google Maps API v3 热图错误 : "Cannot read property ' HeatmapLayer' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24414402/

相关文章:

php - 表中的当年数据按月记录

javascript - 如何在 Javascript 中更改字符串中的特定字符

javascript - 显示/隐藏多个 div

php - 添加文本时停止闪烁(清除框并重新填充)的算法

java - 尝试使用 Intent 获取字符串时,.child() 未设置

android - 如何使用 Google Maps Android API v2 禁用 3d 建筑物

java - 获取Javascript标签内容

javascript - 使用退出键关闭菜单

jquery - 如果选中复选框,则仅更改该元素的样式

javascript - 功能策略已在本文档中禁用地理定位