Google Maps API V3中的API密钥是什么? [英] What's the API Key for in Google Maps API V3?

查看:210
本文介绍了Google Maps API V3中的API密钥是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧版本的API中,我必须使用类似这样的东西将JavaScript插入到页面中,以实现基本功能:




和您的浏览器的控制台会告诉您原因:




Google Maps API错误:MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key- map-error


In the older version of the API, I'd have to insert the javascript into the page using something like this for just basic functionality to work:

http://maps.google.com/maps?file=api&v=2&key=GoogleMapsAPIKey

Where I had to configure the API key for each individual site. Looking at the documentation, it says to get a basic map working I just need this:

http://maps.google.com/maps/api/js?sensor=true/false

Where does the API key fit in? Do I need to worry about it if I just plan on using a basic map and marker and none of the more advanced functions?

I'm also testing on localhost, but the FAQ says I still need to register a key for it, which I haven't done and it still works.

解决方案

As of June 22, 2016 Google Maps V3 no longer supports keyless access so you need to get a key for every (referrer-)domain which has never had a Google Map on it before.

Get your key here: https://developers.google.com/maps/documentation/javascript/get-api-key

and append it to the URL of the script like so:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" type="text/javascript"></script>

If you do not provide an API key you will see this warning instead of your rendered map:

and your browser's console will tell you the reason:

Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

这篇关于Google Maps API V3中的API密钥是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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