簡體   English   中英

Google Maps JavaScript API 3密鑰生成

[英]Google maps javascript API 3 key generation

我正在嘗試使用google maps javasrcipt API 3將google map嵌入我的網站。我已經生成了一個密鑰,並按如下所示輸入了它:

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=AIzSyBZsRvsDrBFh4-kVadHK&sensor=true">
</script>

(查看上一行代碼中的參數key =)。

當我打開應用程序時,我注意到輸入的密鑰無效並且地圖崩潰。

誰能幫助我!

通過javascript加載其他API時會使用瀏覽器密鑰。

您可以使用Maps APIJavascript API簡化收錄程序

<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=true"></script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>

在您的代碼內部(例如Fusion Tables),您可以通過以下方式添加它:

function init() {
    gapi.client.load('fusiontables', 'v1', function() {
        gapi.client.setApiKey( "YOUR_BROWSER_API_KEY_HERE" );
        //Other stuff to do on loading this
        gapi.client.fusiontables.query.sql({sql:["SELECT * FROM", TABLE_NAME].join(' '), fields:'rows, columns'}).execute( function(json) {
            //Do what you need to parse the json response
            //Set up KML Layers
            //etc... make sure to check if maps is loaded too
            json.rows.forEach( function(t) {
                console.log( t );
            });
        });
    });
}

這樣您就可以執行授權(而非OAuth 2.0)的工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM