没有密钥的Google Maps API?

科里

您如何在没有密钥的情况下利用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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Maps Geocoding的API密钥

来自分类Dev

Google Maps API密钥错误

来自分类Dev

加载Google Maps API JavaScript时出现不同的错误(配额,已禁用,错误的API密钥或没有错误)

来自分类Dev

google maps api,提供的API密钥无效

来自分类Dev

Maps API密钥生成

来自分类Dev

Google Maps SDK无法验证API密钥

来自分类Dev

动态设置GMLib的Google Maps Api密钥

来自分类Dev

Wordpress ACF Google Maps Field API密钥

来自分类Dev

无法获取Google Maps JavaScript API密钥

来自分类Dev

难以获取Google Maps的API密钥

来自分类Dev

没有API密钥的Google地理编码

来自分类Dev

要使用Google Maps API,需要哪个API密钥?

来自分类Dev

Google Maps API RefererNotAllowedError

来自分类Dev

Google Maps API DeletedApiProjectMapError

来自分类Dev

Google Maps Api许可

来自分类Dev

Google Maps Api

来自分类Dev

Google Maps REST API

来自分类Dev

Google Maps API请求

来自分类Dev

Google Maps Directions API

来自分类Dev

Google Maps API参数

来自分类Dev

带有API密钥的Google Maps无法在生产环境中使用

来自分类Dev

Google Maps API密钥不适用于所有环境

来自分类Dev

Google Maps API 错误:MissingKeyMapError,但我有一个密钥

来自分类Dev

用于文件:///的Google Maps API密钥引荐来源

来自分类Dev

Google Maps API密钥-街景视图禁止使用403

来自分类Dev

在Android Studio中使用Gradle管理Google Maps API密钥

来自分类Dev

Google Maps Places:为什么需要API密钥?

来自分类Dev

Google Maps iOS API密钥不起作用

来自分类Dev

在GitHub上共享我的Google Maps API密钥是否安全?