TypeError: google.visualization.Map is not a constructor

196 views
Skip to first unread message

Shashank Raghavendra

unread,
Jan 20, 2023, 6:32:59 AM1/20/23
to Google Visualization API
Hey everyone, 

I keep getting the error "TypeError: google.visualization.Map is not a constructor" when I am trying to render a Map. However when I change to  google.visualization.GeoChart this error goes away. I have gone through several sites trying to find an answer for this but to no avail. 

Please help me with this. The code is below:

google.charts.load('current', {
           'packages': ['map'],
           'mapsApiKey': maps_API_key
        });
        google.charts.setOnLoadCallback(drawMarkersMap);
        function drawMarkersMap(){
            data = new google.visualization.DataTable();
            data.addColumn("string","Country");
            data.addColumn("number","Population");
           
            data.addRows([
                ['India',      2761477],
                ['Milan',     1324110],
                ['Naples',    959574],
                ['Turin',     907563],
                ['Russia',   655875],
                ['Genoa',     607906],
                ['Mumbai',   380181],
                ['Florence',  371282],
                ['Fiumicino', 67370],
                ['Anzio',     52192],
                ['Ciampino',  38262]
            ]);
           
            options = {
                zoomLevel: 2,
                showTooltip: true,
                showInfoWindow: true,
                useMapTypeControl: true,
            }
       
            var map = new google.visualization.Map(document.getElementById('chart_div_map'));
            map.draw(data, options);
        }
Reply all
Reply to author
Forward
0 new messages