【问题标题】:Google Heatmap - no pointer on map谷歌热图 - 地图上没有指针
【发布时间】: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


【解决方案1】:

更像这样的东西:http://jsfiddle.net/6JSe7/1/ ?

我所做的只是调低(或调高数字)不透明度,这些点的缩放级别越来越高,但它们几乎不可见(我的意思是几乎无法检测到),并添加了消散选项:

heatmap = new google.maps.visualization.HeatmapLayer({
            data: pointArray,
            dissipating: true,
            radius: 35

        });

        heatmap.setMap(map);
        heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
        heatmap.set('opacity', '0.9');

【讨论】:

  • 现在看起来好多了,但不是我想要的。我试图更好地解释.. 如果您在 Google 上查看演示(您可以找到有关该主题的链接),如果您缩放地图,您可以准确看到 google.maps.LatLng 坐标的位置,但这不会发生在我的演示。有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多