谷歌地图 API 警告: NoApiKeys

我在没有 API 密钥的情况下使用 Google Maps API v3已经有一段时间了,它工作得很好。
它仍然可以工作,但我在控制台得到一个警告:

谷歌地图 API 警告: NoApiKeys Https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

我以标准的方式加入了剧本:

<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>

google.maps.version表示我用的是3.24.2。

在 Google 文档中,我只能看到获得密钥的不同方式,但是没有指示是否需要。我今天注意到了这个警告,我很确定它不是几周前出现的。

目前一切正常,但我担心未来不使用 API 密钥的地图访问将会停止。如果没有必要的话,我是不愿意注册钥匙的。

我该担心吗?

126527 次浏览

A key currently still is not required ("required" in the meaning "it will not work without"), but I think there is a good reason for the warning.

But in the documentation you may read now : "All JavaScript API applications require authentication."

I'm sure that it's planned for the future , that Javascript API Applications will not work without a key(as it has been in V2).

You better use a key when you want to be sure that your application will still work in 1 or 2 years.

Creating and using the key is the way to go. The usage is free until your application reaches 25.000 calls per day on 90 consecutive days.

BTW.: In the google Developer documentation it says you shall add the api key as option {key:yourKey} when calling the API to create new instances. This however doesn't shush the console warning. You have to add the key as a parameter when including the api.

<script src="https://maps.googleapis.com/maps/api/js?key=yourKEYhere"></script>

Get the key here: GoogleApiKey Generation site

I had the same problem and I found out that if you add the URL param ?v=3 you won't get the warning message anymore:

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

Reproduction online

As pointed out in the comments by @Zia Ul Rehman Mughal

Turns out specifying this means you are referring to old frozen version 3.0 not the latest version. Frozen old versions are not updated with bug fixes or anything. But this is good to mention though. https://developers.google.com/maps/documentation/javascript/versions#the-frozen-version

Update 07-Jun-2016

This solution doesn't work anymore.

Google maps requires an API key for new projects since june 2016. For more information take a look at the Google Developers Blog. Also more information in german you'll find at this blog post from the clickstorm Blog.