簡體   English   中英

沒有密鑰的Google Maps API?

[英]Google Maps API without key?

如何在沒有密鑰的情況下使用Google Maps v3 API? 我已經在這個例子中看到了它,但無法弄清楚具體是什么導致它不會出錯。

編輯:如果有人建議,StackOverflow上關於此主題的其他答案已過時且不再適用。

現在需要一把鑰匙 以前它不是必需的,並且在2016年6月22日之前使用沒有密鑰的API的網站已經過豁免,以允許它們繼續工作。

有關其他信息,請參閱此博客文章 (相關文字如下):

自2016年6月22日起,我們對Google Maps API標准計划進行了以下更改:

  1. 我們不再支持無密鑰訪問(任何不包含API密鑰的請求)。 未來的產品更新僅適用於使用API​​密鑰發出的請求。 API密鑰允許我們在需要時聯系開發人員,幫助我們識別行為不當的實現。
  2. 我們已經為新的Google Maps JavaScript API,Static Maps API和街景圖像API實施實施了每天25,000個地圖加載限制。 這些API連續90天的寬限期將於2016年10月12日停用。通過此更改,開發人員可以預測增長計划,而媒體網站和美國公益組織可以通過我們的專門支持計划免費申請更多配額。
  3. 我們已經針對每個API的1,000,000到100,000個請求減少了您可以針對Google Maps JavaScript API,Static Maps API和街景圖像API購買的每日地圖加載最大限制。*我們認為大批量開發人員最好使用Premium Plan許可證,包括技術支持和服務水平協議,通過此更改,我們還在地圖和Web服務API之間創建了標准計划配額之間的一致性。
  4. 我們現在將Google Maps JavaScript API客戶端請求計入關聯的Web服務API的每日限制。*

新政策將立即適用於2016年6月22日或之后創建的所有Maps API實施。

現有應用程序已根據其當前使用情況進行了廣泛使用,以確保它們現在和將來都能繼續運行。 我們還將主動聯系所有現有API密鑰用戶,這些用戶根據使用量增長模式可能會在未來受到影響。 如果您是現有用戶,請花時間閱讀我們的標准計划摘要政策更新,詳細了解每項更改可能如何影響您的實施。

實際上,您發布的鏈接http://www.birdtheme.org/useful/v3largemap.html無需密鑰(控制台中只有一個警告)。 看起來谷歌正在將一些域名列入白名單,以允許在沒有密鑰的情況下使用API​​。

我嘗試使用谷歌地圖API V3顯示OpenStreetMap的瓷磚,但它會產生一個“谷歌地圖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?*阻止發送錯誤的HTTP請求

這樣您就可以訪問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彈出框...對於地理編碼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 -->

從2018年6月11日開始,您無法再使用密鑰而無法使用GoogleMaps API。

資源

我可以在沒有任何api密鑰或javascript代碼的網站中放置位置指示器

我使用Fancybox非常容易地顯示谷歌地圖模式框。

<head>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.6/dist/jquery.fancybox.min.css" />
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.6/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>
<script language="javascript" src="https://maps.google.com/maps/api/js"></script>
    <script>
    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; 
                }
                observer.disconnect();
            }
        }
    });
    var config = { attributes: true, childList: true, characterData: true }
    observer.observe(target, config);
    </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM