Javascript 没有密钥的Google Maps API?

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

Google Maps API without key?

javascriptgoogle-maps-api-3

提问by CoryG

How do you utilize Google Maps v3 API without the key? I've seen it in this examplebut cannot figure out what specifically is causing it not to error out.

如何在没有密钥的情况下使用 Google Maps v3 API?我在这个例子中看到了它,但无法弄清楚是什么导致它不会出错。

Edit: In case someone suggests it, the other answers on this topic on StackOverflow are outdated and no longer applicable.

编辑:如果有人建议,StackOverflow 上有关此主题的其他答案已过时且不再适用。

采纳答案by baptx

Indeed the link you posted http://www.birdtheme.org/useful/v3largemap.htmlworks without key (there is just a warning in the console). It looks like Google is whitelisting some domain names to allow the use of API without key.

实际上,您发布的链接http://www.birdtheme.org/useful/v3largemap.html无需密钥即可工作(控制台中只有一个警告)。看起来谷歌正在将一些域名列入白名单,以允许在没有密钥的情况下使用 API。

I tried to use the Google Maps API v3 to display OpenStreetMap tiles but it produces a "Google Maps API error: MissingKeyMapError" on my localhost while it is working on this site without API key: http://harrywood.co.uk/maps/examples/google-maps/apiv3.html

我尝试使用 Google Maps API v3 来显示 OpenStreetMap 图块,但它在我的本地主机上产生“Google Maps API 错误:MissingKeyMapError”,而它在没有 API 密钥的情况下在此站点上工作:http://harrywood.co.uk/maps /examples/google-maps/apiv3.html

On most websites that don't use an API key, there is an error that prevent the use of Google Maps but you can bypass this censorship.

在大多数不使用 API 密钥的网站上,存在阻止使用 Google 地图的错误,但您可以绕过这种。

Solution if you don't own the server using Google Maps API without key:

如果您没有使用没有密钥的 Google Maps API 拥有服务器,则解决方案:

Block the HTTP request sending the error with an addon like AdBlockPlus and the rule http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?*

使用 AdBlockPlus 和规则等插件阻止发送错误的 HTTP 请求 http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?*

This will give you access to Google Maps API tiles, markers, infoWindow popup... But if you want to use the Geocoding API, you also have to remove your HTTP referer headerwith a browser addon like "Modify Headers".

这将使您能够访问 Google Maps API 图块、标记、infoWindow 弹出窗口……但是如果您想使用地理编码 API,您还必须remove your HTTP referer header使用“修改标题”等浏览器插件。

Solution to add in your web page so every visitors can access Google Maps API without key:

添加到您的网页中的解决方案,以便每个访问者无需密钥即可访问 Google Maps API:

Below is a JavaScript hack I created to use Google Maps API V3 without key and bypass the error message.

下面是我创建的一个 JavaScript hack,用于在没有密钥的情况下使用 Google Maps API V3 并绕过错误消息。

// hack Google Maps to bypass API v3 key (needed since 22 June 2016 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)
var target = document.head;
var observer = new MutationObserver(function(mutations) {
    for (var i = 0; mutations[i]; ++i) { // notify when script to hack is added in HTML head
        if (mutations[i].addedNodes[0].nodeName == "SCRIPT" && mutations[i].addedNodes[0].src.match(/\/AuthenticationService.Authenticate?/g)) {
            var str = mutations[i].addedNodes[0].src.match(/[?&]callback=.*[&$]/g);
            if (str) {
                if (str[0][str[0].length - 1] == '&') {
                    str = str[0].substring(10, str[0].length - 1);
                } else {
                    str = str[0].substring(10);
                }
                var split = str.split(".");
                var object = split[0];
                var method = split[1];
                window[object][method] = null; // remove censorship message function _xdc_._jmzdv6 (AJAX callback name "_jmzdv6" differs depending on URL)
                //window[object] = {}; // when we removed the complete object _xdc_, Google Maps tiles did not load when we moved the map with the mouse (no problem with OpenStreetMap)
            }
            observer.disconnect();
        }
    }
});
var config = { attributes: true, childList: true, characterData: true }
observer.observe(target, config);

This will give you access to Google Maps API tiles, markers, infoWindow popup... For the Geocoding API, you also have to remove your HTTP referer with the HTML meta tag below.

这将使您能够访问 Google Maps API 图块、标记、infoWindow 弹出窗口...对于地理编码 API,您还必须使用下面的 HTML 元标记删除您的 HTTP 引用。

<meta name="referrer" content="no-referrer"> <!-- don't send HTTP referer for privacy purpose and to use Google Maps Geocoding API without key -->

回答by geocodezip

A key is now required. Previously it wasn't required and sites that used the API without a key prior to June 22, 2016 have been grandfathered to allow them to continue to work.

现在需要一个密钥。以前它不是必需的,并且在 2016 年 6 月 22 日之前使用 API 没有密钥的站点已被允许继续工作。

See this blog post for additional information(relevant text below):

有关其他信息,请参阅此博客文章(以下相关文本):

As of June 22, 2016 we are making the following changes to the Google Maps APIs Standard Plan:

  1. We no longer support keyless access (any request that doesn't include an API key). Future product updates are only available for requests made with an API key. API keys allow us to contact developers when required and help us identify misbehaving implementations.
  2. We have implemented a simple 25,000 map loads per day free limit to new Google Maps JavaScript API, Static Maps API, and Street View Image API implementations. The confusing 90-consecutive-day grace period for these APIs is being retired on October 12, 2016. With this change, developers can predictably plan for growth while media sites and US nonprofits can request more quota at no charge via our dedicated support programs.
  3. We have reduced the daily map load maximum limit you can purchase for Google Maps JavaScript API, Static Maps API, and Street View Image API from 1,000,000 to 100,000 requests per API.* We believe higher-volume developers are best served with a Premium Plan license, which includes technical support and a Service Level Agreement, and with this change we've also created consistency between Standard Plan quotas across our maps and web service APIs.
  4. We now count Google Maps JavaScript API client-side requests towards the daily limit of the associated web service API.*

The new policies will apply immediately to all Maps API implementations created on or after June 22nd, 2016.

Existing applications have been grandfatheredbased on their current usage to ensure that they continue to function both now and in the future. We will also be proactively contacting all existing API key users who, based on usage growth patterns, may be impacted in the future. If you're an existing user, please take the time to read our Policy Update for Standard Plan summary for details on how each of these changes might affect your implementation.

自 2016 年 6 月 22 日起,我们将对 Google Maps API 标准计划进行以下更改:

  1. 我们不再支持无密钥访问(任何不包含 API 密钥的请求)。未来的产品更新仅适用于使用 API 密钥提出的请求。API 密钥允许我们在需要时联系开发人员并帮助我们识别行为不端的实现。
  2. 我们对新的 Google Maps JavaScript API、Static Maps API 和 Street View Image API 实现实施了每天 25,000 次地图加载的简单限制。这些 API 令人困惑的连续 90 天宽限期将于 2016 年 10 月 12 日停用。通过此更改,开发人员可以按预期规划增长,而媒体网站和美国非营利组织可以通过我们的专用支持计划免费申请更多配额。
  3. 我们已将您可以为 Google Maps JavaScript API、静态地图 API 和街景图像 API 购买的每日地图加载最大限制从每个 API 的 1,000,000 次请求减少到 100,000 次请求。* 我们相信高级计划许可证最好为大批量开发者提供服务,其中包括技术支持和服务水平协议,通过这一更改,我们还在地图和 Web 服务 API 的标准计划配额之间建立了一致性。
  4. 我们现在将 Google Maps JavaScript API 客户端请求计入相关网络服务 API 的每日限制。*

新政策将立即适用于 2016 年 6 月 22 日或之后创建的所有 Maps API 实现。

现有应用程序已根据其当前使用情况进行祖父处理,以确保它们现在和将来都能继续运行。我们还将根据使用增长模式,主动联系所有现有的 API 关键用户,这些用户在未来可能会受到影响。如果您是现有用户,请花时间阅读我们的标准计划政策更新摘要,详细了解这些更改中的每一个可能如何影响您的实施。

回答by Ted

Starting June 11, 2018, you can no longer use GoogleMaps API without key.

自 2018 年 6 月 11 日起,您将无法再无密钥地使用 GoogleMaps API。

source

来源

回答by hullabaloon

I am able to put location indicator in websites without any api key or javascript code

我可以在没有任何 api 密钥或 javascript 代码的网站中放置位置指示器

I use Fancybox to show a google maps modal box very easily.

我使用 Fancybox 很容易地显示一个谷歌地图模式框。

<head>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.css" />
<script src="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.js"></script>
</head>


<body>
<a data-fancybox="" data-options="{&quot;iframe&quot; : {&quot;css&quot; : {&quot;width&quot; : &quot;80%&quot;, &quot;height&quot; : &quot;80%&quot;}}}" href="https://www.google.com/maps/search/?api=1&amp;query=centurylink+field" class="btn btn-primary">Open Modal Map</a>
</body>