简体   繁体   English

何时需要Google Maps API密钥?

[英]When is a Google Maps API key required?

Recently Google changed it's policy on the use API keys. 最近谷歌改变了使用API​​密钥的政策。 You're now supposed to no longer need an API key to place Google Maps on your website. 您现在不再需要API密钥才能在您的网站上放置Google地图。

And this worked perfectly. 这非常有效。 But now I have this map (without API key) running on my localhost, which works fine. 但是现在我在我的localhost上运行了这张地图(没有API密钥),工作正常。 But as soon as I place it online, I get a popup saying that I need another API key. 但是当我把它放在网上时,我会得到一个弹出窗口,说我需要另一个API密钥。 And on another page on that website, Google Maps does work. 在该网站的另一个页面上,Google地图确实有效。 Could it maybe have something to do with that the map that doesn't work have a lot (30+) of markers on it? 它可能与某些事情有关吗?不起作用的地图上有很多(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插件的一部分。

You do not need an API Key to use Goolge Maps API V3. 您不需要API密钥即可使用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. 我继续设置了API密钥,它实际上是有益的,因为您可以获得使用情况报告。 Also, we haven't seen the false Quota usage problem since then. 此外,从那时起,我们还没有看到错误的配额使用问题。 I thought I would go ahead a share the process: 我以为我会继续分享这个过程:

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' 在左侧导航栏中,选择API下的API&Auth,然后选择“Google Maps JavaScript API v3”

在此输入图像描述

Click the link and then Turn on the API 单击该链接,然后启用API

在此输入图像描述

在此输入图像描述

Go to Credentials under the APIs & Auth section, and click the red 'Create New Key' under the Public API access section. 转到API&Auth部分下的Credentials,然后单击Public API访问部分下的红色“Create New Key”。 Then click Browser Key. 然后单击浏览器密钥。

在此输入图像描述

Make sure you include the star in your Website's name. 确保将明星包含在您网站的名称中。 For example, use mywebsite.com/*. 例如,使用mywebsite.com/*。 This will ensure all pages are authorized to use the API. 这将确保所有页面都被授权使用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>

在此输入图像描述

Long story short, the key is not required, but best practices would indicate that you should use the key. 长话短说,关键不是必需的,但最佳实践表明你应该使用密钥。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM