没有密钥的Google Maps API? [英] Google Maps API without key?

查看:16
本文介绍了没有密钥的Google Maps API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如果有人提出建议,StackOverflow 上有关此主题的其他答案已过时且不再适用.

解决方案

确实是您发布的链接 http://www.Birdtheme.org/useful/v3largemap.html 无需密钥即可工作(控制台中只有一个警告).Google 似乎正在将一些域名列入白名单,以允许无需密钥即可使用 API.

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

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

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

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

这将使您能够访问 Google Maps API 图块、标记、信息窗口弹出窗口...但是,如果您想使用地理编码 API,您还必须使用修改标题"等浏览器插件删除您的 HTTP 引用标头.

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

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

//破解 Google Maps 以绕过 API v3 密钥(自 2016 年 6 月 22 日起需要 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)var target = document.head;var 观察者 = 新的 MutationObserver(function(mutations) {for (var i = 0; mutations[i]; ++i) {//当脚本被添加到 HTML 头部时通知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);如果(字符串){如果 (str[0][str[0].length - 1] == '&') {str = str[0].substring(10, str[0].length - 1);} 别的 {str = str[0].substring(10);}var split = str.split(".");var object = split[0];var 方法 = split[1];窗口[对象][方法]=空;//移除审查消息函数_xdc_._jmzdv6(AJAX回调名称_jmzdv6"因URL而异)//窗口[对象] = {};//当我们移除完整的对象_xdc_时,当我们用鼠标移动地图时,谷歌地图图块没有加载(OpenStreetMap没问题)}观察者断开连接();}}});var config = { 属性:true,childList:true,characterData:true }观察者.观察(目标,配置);

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

<!-- 不要为了隐私目的而发送 HTTP 引用,也不要在没有密钥的情况下使用 Google Maps Geocoding API -->

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

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

解决方案

Indeed the link you posted http://www.birdtheme.org/useful/v3largemap.html works 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.

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

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.

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

Block the HTTP request sending the error with an addon like AdBlockPlus and the rule 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 header with a browser addon like "Modify Headers".

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

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

// 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.

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

这篇关于没有密钥的Google Maps API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆