我有一个谷歌强度地图出现在网页上,但它没有根据不同的状态填满。这是代码 -
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geomap']});
google.setOnLoadCallback(drawMap);
function drawMap() {
console.log("In draw map function");
var test = {{states|safe}};
console.log(test); console.log(test);
var data = google.visualization.arrayToDataTable({{states|safe}});
var options = {};
options['region'] = 'US'
options['dataMode'] = 'regions';
var container = document.getElementById('map_canvas');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
};
</script>
</head>
<body>
<div id='map_canvas'></div>
</body>
</html>
我传递的数据看起来像这样 -
[["State","No of users"],["AL",1957392],["AK",324183],["AZ",1837630],["AR",1062588],....]
我做错了什么?我刚收到美国的默认地图。根据强度,它没有被填满。
答案 0 :(得分:0)
您需要将resolution
选项设置为'provinces'
以获取状态图:
options['resolution'] = 'provinces';
此外,不推荐使用GeoMaps,而是使用新的GeoCharts。加载'geochart'
包:
google.load('visualization', '1', {'packages': ['geochart']});
并使用GeoChart
对象:
var geochart = new google.visualization.GeoChart(container);
geochart.draw(data, options);