2016-07-01 31 views
12

Jak korzystać z Google Maps v3 API bez klucza? Widziałem to w this example, ale nie mogę dowiedzieć się, co konkretnie powoduje to, aby nie błąd.Google Maps API bez klucza?

Edycja: Jeśli ktoś to zasugeruje, inne odpowiedzi na ten temat dotyczące StackOverflow są nieaktualne i nie mają już zastosowania.

Odpowiedz

12

Rzeczywiście link ty pisał http://www.birdtheme.org/useful/v3largemap.html działa bez klucza (jest tylko ostrzeżenie w konsoli). Wygląda na to, że Google umieszcza na białej liście niektóre nazwy domen, aby umożliwić korzystanie z interfejsu API bez klucza.

Próbowałem użyć v3 Google Maps API, aby wyświetlić płytek OpenStreetMap ale daje „błąd API Google Maps: MissingKeyMapError” na moim localhost pracującej na tej stronie bez klucza API: http://harrywood.co.uk/maps/examples/google-maps/apiv3.html

Na większości strony internetowe, które nie używają klucza API, wystąpił błąd, który uniemożliwia korzystanie z Google Maps, ale można ominąć tę cenzurę.

rozwiązanie, jeśli nie jesteś właścicielem serwera przy użyciu Google Maps API bez klucza:

blokować wysyłanie żądania HTTP błędu z dodatku jak AdBlockPlus i rządów http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?*

to daje dostęp do kafelków API Map Google, znaczników, informacji Okienko popup ... Ale jeśli chcesz korzystać z interfejsu API geokodującego, musisz także remove your HTTP referer header dodać do przeglądarki dodatek "Modyfikuj nagłówki".

Rozwiązanie dodać na swojej stronie internetowej, więc każdy odwiedzający może uzyskać dostęp do Google Maps API bez klucza:

Poniżej JavaScript włamać stworzyłem w użyciu Google Maps API V3 bez klucza i obejść się komunikat o błędzie.

// 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); 

To da Ci dostęp do Google Maps API płytek, markery, infoWindow popup ... dla API geokodowanie, trzeba także usunąć HTTP_REFERER z HTML meta tag poniżej.

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

Dziękuję, to działa dla mnie :) – user3719857

+0

Tak, działa, ale pierwsze żądanie API jest bardzo powolne (5 do 10 sekund), z powodu opóźnionego pobrania pliku Google QuotaService.RecordEvent, a następnie wszelkich innych żądanie działa dobrze ... Jakieś wyjaśnienie? –

+0

@DrFred Widziałem, że uzyskanie pierwszej odpowiedzi z interfejsu API geokodującego zajmuje nieco więcej czasu. Problem opóźnień z pewnością bierze się z serwerów Google próbujących uwierzytelnić użytkownika za pomocą klucza API, ale cieszę się, że mam działające rozwiązanie i mam nadzieję, że obejście to zadziała tak długo, jak to możliwe. Przed tym hackerem nie mogłem nawet przetestować Google Maps API z localhost bez klucza API. Gdybym pracował nad nowym projektem, z pewnością skorzystałbym z OpenStreetMap dla darmowych map i pozbyć się tych ograniczeń. – baptx

18

A key is now required. Wcześniej nie było to wymagane, a witryny korzystające z interfejsu API bez klucza przed 22 czerwca 2016 r. Zostały udoskonalone, aby umożliwić im kontynuowanie pracy.

Zobacz this blog post for additional information (odpowiedni tekst poniżej):

As of June 22, 2016 we are making the following changes to the Google Maps APIs Standard Plan:

  1. We no longer support keyless access (any request that doesn't include an API key). Future product updates are only available for requests made with an API key. API keys allow us to contact developers when required and help us identify misbehaving implementations.
  2. We have implemented a simple 25,000 map loads per day free limit to new Google Maps JavaScript API, Static Maps API, and Street View Image API implementations. The confusing 90-consecutive-day grace period for these APIs is being retired on October 12, 2016. With this change, developers can predictably plan for growth while media sites and US nonprofits can request more quota at no charge via our dedicated support programs.
  3. We have reduced the daily map load maximum limit you can purchase for Google Maps JavaScript API, Static Maps API, and Street View Image API from 1,000,000 to 100,000 requests per API.* We believe higher-volume developers are best served with a Premium Plan license, which includes technical support and a Service Level Agreement, and with this change we've also created consistency between Standard Plan quotas across our maps and web service APIs.
  4. We now count Google Maps JavaScript API client-side requests towards the daily limit of the associated web service API.*

The new policies will apply immediately to all Maps API implementations created on or after June 22nd, 2016.

Existing applications have been grandfathered based on their current usage to ensure that they continue to function both now and in the future. We will also be proactively contacting all existing API key users who, based on usage growth patterns, may be impacted in the future. If you’re an existing user, please take the time to read our Policy Update for Standard Plan summary for details on how each of these changes might affect your implementation.

+1

Kluczem ** nie jest wymagane ** Zamieściłem link, który działa bez klucza. – CoryG

+0

Nie o to chodzi. Możesz pobrać ten sam kod ze strony i uruchomić go lokalnie bez żadnych błędów, ergo robią coś, aby nie musieć używać klucza w tym kodzie. Pytanie nie ma żadnego wpływu na to, co Google mówi, jest lub jest nie w porządku, ale opiera się całkowicie na tym, co jest. – CoryG

+3

Lokalny host/system plików może pracować bez klucza. – geocodezip

0
<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> 
+0

nie działa poza stroną lokalną. – CoryG

+0

użyj go w sekcji head, użyłem w moich kilku projektach – Anup

Powiązane problemy