Google Maps javascript API 3代码 [英] Google maps javascript API 3 key generation

查看:111
本文介绍了Google Maps javascript API 3代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用google maps javasrcipt API 3将google地图嵌入到我的网站中。我已经生成了一个密钥,并输入如下:

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

(查看上一行代码中的参数key =)。



当我打开我的应用程序时,我收到一个通知,指出我输入的密钥不会被占用,地图崩溃。



解决方案

当您通过javascript加载其他API时,浏览器键被使用。



您可以使用 Maps API Javascript API

 < script src =https://maps.googleapis.com/maps/api/js?v=3&sensor=true>< ; /脚本> 
< 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);
//加载此
的其他东西gapi.client.fusiontables.query.sql({sql:[SELECT * FROM,TABLE_NAME] .join(''),fields:'rows,columns'})execute(function(json){
//做你需要解析的json响应
//设置KML图层
// etc ...确保检查地图是否加载
json.rows.forEach(function(t){
console.log(t);
}) ;
});
});
}

您将能够执行授权(而不是OAuth 2.0)方式。


I am trying to embed a google map into my website using google maps javasrcipt API 3. I have generated a key and entered it as follow:

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

(Look at the parameter key= in the previous line of code).

When I open my application , I get a notice that the key I entered is not valide and the map crashes.

Can anyone help me on that !

解决方案

The browser key is used when you load other APIs through the javascript.

You can keep your include simplified with the Maps API and Javascript 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>

and inside your code, say Fusion Tables, you can add it this way:

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 );
            });
        });
    });
}

And you will be able to do authorized (not OAuth 2.0) stuff in that manner.

这篇关于Google Maps javascript API 3代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆