baptx

Google Maps API without key

Jul 6th, 2020
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. https://stackoverflow.com/questions/38148097/google-maps-api-without-key/38809129#38809129
  2.  
  3. Indeed the link you posted http://www.birdtheme.org/useful/v3largemap.html works without key (there is just a warning in the console).
  4. It looks like Google is whitelisting some domain names to allow the use of API without key.
  5.  
  6. 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
  7.  
  8. 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.
  9.  
  10. **Solution if you don't own the server using Google Maps API without key:**
  11.  
  12. Block the HTTP request sending the error with an addon like AdBlockPlus and the rule `http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?*`
  13.  
  14. This will give you access to Google Maps API tiles, markers, infoWindow popup...
  15. 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".
  16.  
  17. **Solution to add in your web page so every visitors can access Google Maps API without key:**
  18.  
  19. Below is a JavaScript hack I created to use Google Maps API V3 without key and bypass the error message.
  20.  
  21. // 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)
  22. var target = document.head;
  23. var observer = new MutationObserver(function(mutations) {
  24. for (var i = 0; mutations[i]; ++i) { // notify when script to hack is added in HTML head
  25. if (mutations[i].addedNodes[0].nodeName == "SCRIPT" && mutations[i].addedNodes[0].src.match(/\/AuthenticationService.Authenticate?/g)) {
  26. var str = mutations[i].addedNodes[0].src.match(/[?&]callback=.*[&$]/g);
  27. if (str) {
  28. if (str[0][str[0].length - 1] == '&') {
  29. str = str[0].substring(10, str[0].length - 1);
  30. } else {
  31. str = str[0].substring(10);
  32. }
  33. var split = str.split(".");
  34. var object = split[0];
  35. var method = split[1];
  36. window[object][method] = null; // remove censorship message function _xdc_._jmzdv6 (AJAX callback name "_jmzdv6" differs depending on URL)
  37. //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)
  38. }
  39. observer.disconnect();
  40. }
  41. }
  42. });
  43. var config = { attributes: true, childList: true, characterData: true }
  44. observer.observe(target, config);
  45.  
  46. This will give you access to Google Maps API tiles, markers, infoWindow popup...
  47. For the Geocoding API, you also have to remove your HTTP referer with the HTML meta tag below.
  48.  
  49. <meta name="referrer" content="no-referrer"> <!-- don't send HTTP referer for privacy purpose and to use Google Maps Geocoding API without key -->
RAW Paste Data