How to set an API key when using Google's script loader?
Asked Answered
S

2

6

I registered my project and generated a browser key at https://code.google.com/apis/console/.

Now how do I use that key when using the Google Script Loader?

I've been doing this, which works (with or without the key parameter), but even after several weeks the API console shows no requests:

<script src=//www.google.com/jsapi?key=my_key"></script>
<script>
    google.load('maps', '3.10', { other_params : 'libraries=places&sensor=false', callback : ... })
</script>
Shorthanded answered 19/1, 2013 at 1:21 Comment(0)
H
13

The key is useless for the jsapi, you must append it to other_params:

<script>
    google.load('maps', '3', {
        other_params: 'key=my_key',
        callback: function(){}
    });
</script>
Haddad answered 19/1, 2013 at 3:23 Comment(0)
R
0

When using charts/loader you have to do something like this:

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    google.charts.load('current', {
        'packages':['geochart'],
        // Note: you will need to get a mapsApiKey for your project.
        // See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
        'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
    });
    google.charts.setOnLoadCallback(drawRegionsMap);
    ...
</script>

Note the mapsApiKey property.

As described in https://developers.google.com/chart/interactive/docs/gallery/geochart

Rhodos answered 16/12, 2017 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.