Same problem as described in ERROR: Google Maps API error: MissingKeyMapError, except that:
- this is with Google Charts instead of Google Maps
- unlike for Google Maps, there seems to be no documentation on how to get a key or use a key when it comes to charts / visualization (e.g.
var map = new google.visualization.GeoChart(...)
Googling "google charts MissingKeyMapError" yields NOTHING. - this error does not seem to occur if the html+js is served from a web server running on localhost. It only occurs when that html+js is saved to file and then the file is opened in a browser
- this error only seems to occur when setting displayMode = 'text' (maybe in doing so Charts is calling Maps and I need to somehow pass some Maps API key inside there?)
This problem did not occur a couple of days ago. Googling "MissingKeyMapError charts" yields NOTHING.
Here's the code snipped that seems to recreate the error:
var map = new google.visualization.GeoChart(document.getElementById('map2-container')),
map_options = {
region: 'US',
resolution: 'provinces',
displayMode: 'text',
};
map.draw(stateText, map_options);
Any suggestions as to a workaround? Maybe some undocumented API options / hooks / etc?
========== UPDATE =============
I implemented the accepted answer as follows. There may be better ways than this:
<script>
function init() {
var script = document.createElement('script');
script.src = 'http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=drawMap&key=my_key';
document.body.appendChild(script);
google.load("visualization", "1.1", { packages:["geochart"], callback: 'drawMap'});
}
function drawMap() {
...
var map = new google.visualization.GeoChart(...)
...
}
</script>
...
<body onload="init()">