您如何在没有密钥的情况下利用Google Maps v3 API?在此示例中,我已经看到了它,但是无法弄清楚是什么导致了它不会出错。
编辑:如果有人建议,关于StackOverflow的此主题的其他答案已过时,不再适用。
确实,您发布的链接http://www.birdtheme.org/useful/v3largemap.html无需钥匙即可工作(控制台中仅显示警告)。Google似乎将某些域名列入了白名单,以允许使用不带密钥的API。
我尝试使用谷歌地图API V3显示OpenStreetMap的瓷砖,但它会产生一个“谷歌地图API的错误:MissingKeyMapError”在我的本地是工作在这个网站没有API密钥,而:http://harrywood.co.uk/maps /examples/google-maps/apiv3.html
在大多数不使用API密钥的网站上,都会出现一个错误,阻止您使用Google Maps,但是您可以绕过此审查制度。
如果您不使用没有密钥的Google Maps API来拥有服务器,则可以采用以下解决方案:
使用AdBlockPlus等附加组件和规则阻止HTTP请求发送错误 http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?*
这将使您能够访问Google Maps API磁贴,标记,infoWindow弹出窗口……但是,如果要使用地理编码API,还必须remove your HTTP referer header
使用浏览器插件(如“修改标题”)。
在您的网页中添加的解决方案,以便每个访问者都可以访问Google Maps API,而无需输入密钥:
以下是我创建的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);
这将使您可以访问Google Maps API磁贴,标记,infoWindow弹出窗口。对于Geocoding API,还必须使用下面的HTML meta标签删除HTTP引用。
<meta name="referrer" content="no-referrer"> <!-- don't send HTTP referer for privacy purpose and to use Google Maps Geocoding API without key -->
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句