Google Maps API无钥匙? [英] Google Maps API without key?

查看:366
本文介绍了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: //maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?*



您可以使用Google Maps API瓷砖,标记,infoWindow弹出...
但是,如果您想使用Geocoding API,您还必须使用浏览器插件(如修改标题)来移除您的HTTP referer标题。



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

下面是我为使用Google Maps API V3而创建的一个JavaScript黑客,它不包含密钥并跳过了错误消息。

  //破解Google绕过API v3键的地图(自2016年6月22日起需要http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)
var target = document 。头;
var observer = new MutationObserver(function(mutations){
for(var i = 0; mutations [i]; ++ i){//在HTML头中添加黑客脚本时通知
if(mutations [i] .addedNodes [0] .nodeName ==SCRIPT&&&& amp;& amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& amp; amp;& {
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; //删除审查消息函数_xdc _._ jmzdv6(AJAX callback name_jmzdv6 根据URL的不同而不同)
// window [object] = {}; //当我们移除完整对象_xdc_时,当我们用鼠标移动地图时,Google地图切片没有加载(OpenStreetMap没有问题)
}
observer.disconnect();
}
}
});
var config = {attributes:true,childList:true,characterData:true}
observer.observe(target,config);

这将使您可以访问Google Maps API切片,标记,infoWindow弹出...
对于Geocoding API,您还必须使用下面的HTML元标记移除HTTP引用程序。

 < meta name = referrercontent =no-referrer> <! - 不要为了隐私目的而发送HTTP referer,也不要在没有密钥的情况下使用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天全站免登陆