Search code examples
javascripthtmlcssgoogle-maps-api-3

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


I know that it is against the Google Maps API ToS to remove the Google branding or the ToS link that are overlaid across the bottom of the map, but I'm using the maps API to display a video game map, and the Google logo links to the main Google Maps site in such a way that it sends you to a real-world map at the same world coordinates as the current view of my in-game map, which completely doesn't make sense for this use case. Is there any way to disable the link to Google Maps from clicking on the Google logo? I've seen CSS examples for removing the logo, but the link remains. I don't even care about having the logo, and for the sake of the ToS, I'd prefer to leave it there, but is there any way to disable the link?


Solution

  • You could always use JavaScript to make the link do nothing after the map has loaded:

    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'd probably have to redo this when the map is changed (cache the anchor tag so you don't have to search for it each time).