javascript - 谷歌热图 - map 上没有指针

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

我正在使用谷歌热图,我正在尝试在 map 上加载超过 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 个指针。

我需要你的帮助! 谢谢!

最佳答案

更像是这样的: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');

关于javascript - 谷歌热图 - map 上没有指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407123/

相关文章:

javascript - 如何在 Google map 中收听用户生成的缩放?

javascript - 谷歌地图 API v3 : custom markers not clickable on mobile devices

javascript - 如何动态地将组件传递给父组件

javascript - Jest 测试上下文/监视在函数外部创建的模拟变量(类级别)

javascript - 谷歌地图上的 d3 图与节点之间的链接

google-maps - 如何指定WMS请求中的参数层?

javascript - 不用 jQuery 处理丢失的图像

javascript - 是否可以将回调附加到委托(delegate)事件监听器 (.on()) 的设置?

cocoa-touch - 加载所有可见 map 图 block 时调用的 Google map 事件

javascript - 了解用于网页的 google places api