javascript 什么时候需要 Google Maps API 密钥?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5128223/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:03:47  来源:igfitidea点击:

When is a Google Maps API key required?

javascriptapigoogle-mapsmapapi-key

提问by Thomas

Recently Google changed it's policy on the use API keys. You're now supposed to no longer need an API key to place Google Maps on your website.

最近谷歌改变了它关于使用 API 密钥的政策。您现在应该不再需要 API 密钥来将 Google 地图放置在您的网站上。

And this worked perfectly. But now I have this map (without API key) running on my localhost, which works fine. But as soon as I place it online, I get a popup saying that I need another API key. And on another page on that website, Google Maps does work. Could it maybe have something to do with that the map that doesn't work have a lot (30+) of markers on it?

这工作得很好。但是现在我在我的本地主机上运行了这张地图(没有 API 密钥),它工作正常。但是一旦我将它放到网上,我就会收到一个弹出窗口,提示我需要另一个 API 密钥。在该网站的另一个页面上,谷歌地图确实有效。它可能与不起作用的地图上有很多(30+)标记有关吗?

Actually using an API key wouldn't be a very nice solution to me, as this is part of a Wordpress plugin used on many websites.

实际上,使用 API 密钥对我来说并不是一个很好的解决方案,因为这是许多网站上使用的 Wordpress 插件的一部分。

采纳答案by Shad

Sounds like you're running v2~ time to upgrade, or get a key for the domain you want to run it on: Google Maps V2 API Key Request

听起来您正在运行 v2~ 是时候升级了,或者获取要运行它的域的密钥: Google Maps V2 API 密钥请求

回答by Mr. B

You do not need an API Key to use Goolge Maps API V3. However, we just experienced an issue where Google reported that we had exceeded our limit, even though we didn't (Development Server). I went ahead and set up an API Key, and its actually beneficial, because you then get usage reporting. Also, we haven't seen the false Quota usage problem since then. I thought I would go ahead a share the process:

您不需要 API 密钥即可使用 Goolge Maps API V3。但是,我们刚刚遇到了一个问题,即 Google 报告我们已经超出了我们的限制,即使我们没有(开发服务器)。我继续设置了一个 API 密钥,它实际上是有益的,因为您随后会获得使用情况报告。此外,从那时起我们就没有看到错误的配额使用问题。我想我会继续分享这个过程:

Goto https://console.developers.google.com/

转到https://console.developers.google.com/

Click the red 'Create Project' button

单击红色的“创建项目”按钮

Give your project a name and Google will automatically give it an ID

给你的项目起个名字,Google 会自动给它一个 ID

Wait until the Spinny on the bottom says your project is complete.

等到底部的 Spinny 显示您的项目已完成。

In the left hand nav, select APIs Under APIs & Auth, and select 'Google Maps JavaScript API v3'

在左侧导航中,选择 APIs & Auth 下的 APIs,然后选择“Google Maps JavaScript API v3”

enter image description here

在此处输入图片说明

Click the link and then Turn on the API

单击链接,然后打开 API

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Go to Credentials under the APIs & Auth section, and click the red 'Create New Key' under the Public API access section. Then click Browser Key.

转到 API 和身份验证部分下的凭据,然后单击公共 API 访问部分下的红色“创建新密钥”。然后单击浏览器密钥。

enter image description here

在此处输入图片说明

Make sure you include the star in your Website's name. For example, use mywebsite.com/*. This will ensure all pages are authorized to use the API.

确保在您的网站名称中包含星号。例如,使用 mywebsite.com/*。这将确保所有页面都被授权使用 API。

Copy the key into your Javascript reference to the Google Maps API, like so:

将密钥复制到您对 Google Maps API 的 Javascript 引用中,如下所示:

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

enter image description here

在此处输入图片说明

Long story short, the key is not required, but best practices would indicate that you should use the key.

长话短说,密钥不是必需的,但最佳实践表明您应该使用密钥。