2
votes

i'm using google heat map and i'm trying to load over 1000 pointer on the map, but i'm not sure it's working.

This is my code:

        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);

I've created a demo with the complete code at this link: http://jsfiddle.net/8b85R/

fixed fiddle (button clicks work)

I didn't understand why i've a lot blue areas, but only 2 pointer! i was expecting something more similar to the Google Demo ( https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap ) where you can find all the 500 pointers.

I need your help! Thank you!

1
What do you mean by a "pointer"? A heatmap isn't going to show individual points. Your jsfiddle has errors when you click on the buttons. fixed fiddle (that zooms to show all the points) - geocodezip
For "pointer" i mean the exact position for the google.maps.LatLng coordinates on map - MassiCiaoCiao

1 Answers

1
votes

Something more like this: http://jsfiddle.net/6JSe7/1/ ?

All I did was dial down (or up number wise) the opacity, the points were there at increasing zoom levels but they were barely visible (by which I mean pretty well undetectable), and added the dissipating option:

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');