Google Maps API v3. Remove the link "Click to see this area on Google Maps."

I know that against the Google Maps API ToS, remove the Google branding or ToS link at the bottom of the map, but I use the map API to display a video game map, and the Google Logo links to the main Google Maps website in such a way that it sends you to a real world map in the same world coordinates as the current view of my game map, which makes absolutely no sense for this use case. Is there a way to disable the link to Google Maps by clicking on the Google logo? I saw CSS examples for removing the logo, but the link remains. I don’t even care about having a logo for ToS, I would rather leave it there, but is there a way to disable the link?

+4
source share
2 answers

You can always use JavaScript so that the link does nothing after loading the map:

var anchors = document.getElementsByTagName('a'), l = anchors.length, i, a; for (i = 0; i < l; i++) { a = anchors[i]; if (a.href.indexOf('maps.google.com/maps?') !== -1) { a.title = ''; a.onclick = function () { return false; }; } } 

You will probably have to redo this when the map is changed (cache the anchor tag so you don't look for it every time).

+4
source

You can connect to the "idle" event on the map and then use jQuery to remove the link as follows:

  google.maps.event.addListenerOnce(map, 'idle', function (e) { $('a[title="Click to see this area on Google Maps"]').remove(); }); 

That would break, of course, if they ever changed the text that was defined for the title attribute, so maybe someone else could offer a better selector - one that will look at the href part, for example.

Regardless of whether any terms of use violate the terms of use, I can not comment.

0
source

Source: https://habr.com/ru/post/1488364/


All Articles