Javascript Google Maps API V3 中的 API 密钥是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2769148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the API Key for in Google Maps API V3?
提问by Brandon
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:
在旧版本的 API 中,我必须使用类似这样的东西将 javascript 插入到页面中,才能使基本功能正常工作:
http://maps.google.com/maps?file=api&v=2&key=GoogleMapsAPIKey
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:
我必须为每个站点配置 API 密钥。查看文档,它说要使基本地图正常工作,我只需要:
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?
API 密钥适用于何处?如果我只是打算使用基本的地图和标记而不使用更高级的功能,我是否需要担心?
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.
我也在本地主机上进行测试,但常见问题解答说我仍然需要为它注册一个密钥,但我还没有这样做,但它仍然有效。
采纳答案by Seybsen
As of June 22, 2016 Google Maps V3 no longer supports keyless accessso you need to get a key for every (referrer-)domain which has never had a Google Map on it before.
自 2016 年 6 月 22 日起,Google Maps V3 不再支持无密钥访问,因此您需要为之前从未有过 Google 地图的每个(推荐人-)域获取密钥。
Get your key here: https://developers.google.com/maps/documentation/javascript/get-api-key
在此处获取您的密钥:https: //developers.google.com/maps/documentation/javascript/get-api-key
and append it to the URL of the script like so:
并将其附加到脚本的 URL 中,如下所示:
<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:
如果您不提供 API 密钥,您将看到此警告而不是渲染的地图:
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 错误:MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
回答by Dan Diplo
Whilst it is true that V3 of the Google Maps API does not requirean API key, it is there for a reason. Google recently introduced the following usage limits:
虽然谷歌地图 API 的 V3 确实不需要API 密钥,但它存在是有原因的。谷歌最近推出了以下使用限制:
Web sites and applications using each of the Maps API may at no cost generate:
- up to 25,000 map loads per day for each API
- up to 2,500 map loads per day that have been modified using the Styled Maps feature
使用每个 Maps API 的网站和应用程序可能会免费生成:
- 每个 API 每天最多加载 25,000 个地图
- 每天最多 2,500 个已使用样式化地图功能修改的地图加载
In order to monitor usage an API key is necessary, as the developer notes make clear:
为了监控使用情况,API 密钥是必要的,正如开发人员所指出的那样:
All Maps API applications should load the Maps API using an API key. Using an API key enables you to monitor your application's Maps API usage, and ensures that Google can contact you about your application if necessary. If your application's Maps API usage by exceeds the Usage Limits, you must load the Maps API using an API key in order to purchase additional quota.
所有 Maps API 应用程序都应使用 API 密钥加载 Maps API。使用 API 密钥可让您监控应用程序的 Maps API 使用情况,并确保 Google 可以在必要时就您的应用程序与您联系。如果您的应用程序的 Maps API 使用超过使用限制,您必须使用 API 密钥加载 Maps API 以购买额外配额。
So whilst you don't need to have an API key it is useful if you want to monitor your usage and also required if you buy additional usage quota.
因此,虽然您不需要 API 密钥,但如果您想监控您的使用情况并且购买额外的使用配额也需要它,它会很有用。
回答by Ossama
V3 of the Google Maps API does not require an API key. So you're good to go.
Google Maps API V3 不需要 API 密钥。所以你可以走了。
Edit: In the time since I answered this question Google released support for API keys in v3, letting you see usage of your API site in Google's developer console. The original answer is still accurate: API keys are not required, but they are now recommended.
编辑:自从我回答这个问题以来,Google 在 v3 中发布了对 API 密钥的支持,让您可以在 Google 的开发者控制台中查看 API 站点的使用情况。原始答案仍然准确:不需要 API 密钥,但现在建议使用它们。
回答by Bakhtawar GIll
Under Google Map's Api's choose Google Maps JavaScript API Enable the Api. Go to credentials section.Choose create Credentials. choose API Key from the popup,and then choose browser key from the proceeding popup. .
在 Google Map's Api's 下选择 Google Maps JavaScript API Enable the Api。转到凭据部分。选择创建凭据。从弹出窗口中选择 API 密钥,然后从进行中的弹出窗口中选择浏览器密钥。.
6.Replace the YOUR_API_KEY with your own api key obtained
6.用自己获取的api key替换YOUR_API_KEY
回答by user1701556
You can't use google maps in Android app unless you create a google map key. You need to use keytool to generate MD5 and use that to generate google map key on google map website. keytool should be located on your computer where you have sdk installed. I have generated developer google map key, and I have noticed that key is only good for developing Android app on that particular computer. If you are going to develop Android app on an another computer then you need to generate another google map key for that computer. If you don't see a google map on your Android app but rather you see a grid, this could mean that your google map key is invalid.
除非您创建谷歌地图密钥,否则您无法在 Android 应用中使用谷歌地图。您需要使用 keytool 生成 MD5 并使用它在谷歌地图网站上生成谷歌地图密钥。keytool 应该位于安装了 SDK 的计算机上。我已经生成了开发人员谷歌地图密钥,我注意到该密钥仅适用于在该特定计算机上开发 Android 应用程序。如果您打算在另一台计算机上开发 Android 应用程序,那么您需要为该计算机生成另一个谷歌地图密钥。如果您在 Android 应用程序上没有看到谷歌地图,而是看到了一个网格,这可能意味着您的谷歌地图密钥无效。


