【发布时间】:2014-01-28 13:39:11
【问题描述】:
我正在使用谷歌热图,我试图在地图上加载超过 1000 个指针,但我不确定它是否正常工作。
这是我的代码:
var map, pointarray, heatmap;
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
]
var taxiData = [
new google.maps.LatLng(43.3128954, 10.5320177),
new google.maps.LatLng(43.4121300, 10.4157520),
....
new google.maps.LatLng(43.3116784, 10.5298907),
new google.maps.LatLng(43.3416850, 10.5290120)
]
function initialize() {
var mapOptions = {
zoom: 13,
dissipating: false,
center: new google.maps.LatLng(43.3128954, 10.5320177),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
pointArray = new google.maps.MVCArray(taxiData);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
function toggleHeatmap() {
heatmap.setMap(heatmap.getMap() ? null : map);
}
function changeGradient() {
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
]
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
function changeRadius() {
heatmap.set('radius', heatmap.get('radius') ? null : 20);
}
function changeOpacity() {
heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}
google.maps.event.addDomListener(window, 'load', initialize);
我在此链接上创建了一个包含完整代码的演示:http://jsfiddle.net/8b85R/
fixed fiddle(按钮点击有效)
我不明白为什么我有很多蓝色区域,但只有 2 个指针!我期待更类似于 Google 演示 (https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap) 的内容,您可以在其中找到所有 500 个指针。
我需要你的帮助! 谢谢!
【问题讨论】:
-
“指针”是什么意思?热图不会显示单个点。单击按钮时,您的 jsfiddle 出现错误。 fixed fiddle(放大显示所有点)
-
对于“指针”,我指的是地图上 google.maps.LatLng 坐标的确切位置
标签: javascript google-maps google-maps-api-3 heatmap