35

So I'm working on a new web app that has a big focus on maps. Using Google Maps API v3 and really happy with it but noticed that the points of interest (POI's) have automatically bubbles with more details and a link to the Google Places page. I don't want these. Here is my code:

map = new google.maps.Map(document.getElementById("map"), {
    center:new google.maps.LatLng(default_latitude,default_longitude),
    zoom:11,
    mapTypeId:google.maps.MapTypeId.ROADMAP,
    mapTypeControl:false,
    panControl:false
});

I know you can remove the POI's entirely. Here is my code for that:

map = new google.maps.Map(document.getElementById("map"),{
    center:new google.maps.LatLng(default_latitude,default_longitude),
    zoom:11,
    mapTypeId:google.maps.MapTypeId.ROADMAP,
    mapTypeControl:false,
    panControl:false,
    styles:[{
        featureType:"poi",
        elementType:"labels",
        stylers:[{
            visibility:"off"
        }]
    }]
});

This removes everything entirely and I still would like to see the labels as I think they bring value but just think the bubbles are too much of a distraction.

For reference here is the bubble I want to remove:

Example

And here is the same map with POI's removed entirely:

Example

Quantum
  • 1,456
  • 3
  • 26
  • 54
Andrew G. Johnson
  • 26,603
  • 30
  • 91
  • 135
  • have you tried using a second mapTile layer that's simply a 256x256 blank png? you could set it as the default mapType and if you're lucky, it's z-index is above the infowindow triggers for the POI's. I'm not gonna try it because I got other worries :) but seriously, I recall having built a map with a second layer with custom map tiles on top of the roadmap and if I'm not mistaken, it caused some marker events to no longer be captured... – tim Jul 13 '12 at 01:56
  • Another approach: Listen for map click events (as we all do) and if `event.placeId` exists, use `event.stop()` to inhibit the native infoWindow. Then you can do your own logic, like a custom infoWindow you track. See: https://stackoverflow.com/a/61310243/4378314 – Kalnode Aug 24 '22 at 20:28

8 Answers8

24

Editor's note: this answer was applicable until version 3.23. Since version 3.24 released in 2016, you can use clickableIcons map option. See xomena's answer.

Version ~3.12 fix. Demo

Here is a new patch that works again. I have tested it with version 3.14.

Now we gonna patch set() instead of open().

function fixInfoWindow() {
    // Here we redefine the set() method.
    // If it is called for map option, we hide the InfoWindow, if "noSuppress"  
    // option is not true. As Google Maps does not know about this option,  
    // its InfoWindows will not be opened.

    var set = google.maps.InfoWindow.prototype.set;

    google.maps.InfoWindow.prototype.set = function (key, val) {
        if (key === 'map' && ! this.get('noSuppress')) {
            console.warn('This InfoWindow is suppressed.');
            console.log('To enable it, set "noSuppress" option to true.');
            return;
        }

        set.apply(this, arguments);
    }
}

What you have to do is set option noSuppress to true for your own InfoWindow's in order to open them, for example:

var popup = new google.maps.InfoWindow({
    content: 'Bang!',
    noSuppress: true
});

popup.setPosition(new google.maps.LatLng(-34.397, 150.644));

popup.open(map);

or:

var popup = new google.maps.InfoWindow({
    content: 'Bang!',
});

popup.set('noSuppress', true);
popup.setPosition(new google.maps.LatLng(-34.397, 150.644));

popup.open(map);
daphshez
  • 9,272
  • 11
  • 47
  • 65
jsmarkus
  • 1,482
  • 1
  • 16
  • 21
  • 1
    That's really cool! With Your code that's very simple to do anything with POI. For example, here I added custom button to POI infoWindow: http://jsfiddle.net/kasheftin/935Km/. And that's simple to add logging info and watch the call stack of every inner method. Here I did it for google.maps.InfoWindow.prototype: http://jsfiddle.net/kasheftin/935Km/1/. – Kasheftin Feb 19 '14 at 15:13
  • If you use something like the [InfoBox plugin](http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/docs/reference.html), setting the option `noSuppress` is superfluous. As long as you open your custom info windows through e.g. InfoBox, the patched `set` will not be called. Tested this myself with Google Maps API v3. – Markus Hofmann Dec 26 '14 at 16:13
  • 1
    For a reliable user experience, use the new clickableIcons property in MapOptions (see xomena's answer below) – miguev Jun 13 '16 at 07:51
16

Starting from version 3.24 the Maps JavaScript API has a property clickableIcons in MapOptions object:

https://developers.google.com/maps/documentation/javascript/3.exp/reference#MapOptions

You can use this property to turn off clickable icons on maps by setting the clickableIcons property to false. Also exists a setClickableIcons() method.

Please look at this example: http://jsbin.com/liyamecoqa/edit?html,output

xomena
  • 31,125
  • 6
  • 88
  • 117
8

No longer works, since update of Google Maps API.

I've found it finally!

Here is the demo: http://jsfiddle.net/fbDDZ/14/ (clicking "open" or POI does nothing, clicking "open please" opens InfoWindow)

The idea is to patch InfoWindow.prototype.open so to allow it accept the third argument. Google does not pass it, but we should.

The code:

function fixInfoWindow() {
    var proto = google.maps.InfoWindow.prototype,
        open = proto.open;
    proto.open = function(map, anchor, please) {
        if (please) {
            return open.apply(this, arguments);
        }
    }
}

Google opens InfoWindow on POI like that:

myInfoWin.open(map, poiMarker)

The window will not open, because Google didnt say "please". That is how we should open our info windows:

myInfoWin.open(map, poiMarker, true);
Tomas
  • 57,621
  • 49
  • 238
  • 373
jsmarkus
  • 1,482
  • 1
  • 16
  • 21
  • 1
    I hoped this work would but when I tried using this and it doesn't seem to work, the patched version of `open` never seems to be called. I'm definitely calling `fixInfoWindow` after everything else has loaded.. – thom_nic Feb 22 '13 at 18:14
  • 2
    This no longer works, proto.open is never called. The demo also no longer works: http://jsfiddle.net/fbDDZ/14/ Anyone know the new way? Thanks. – gdonald Feb 26 '13 at 01:54
  • 1
    Well, so they changed it in Maps API 3.12... Bad news, but i'll be working at workaround. Thanks for reporting it. – jsmarkus Mar 05 '13 at 07:50
  • 1
    It's also patched back to 3.11 but 3.10 still allows this trick for now. My concern about this is that Google normally disables this behaviour on mobile, but it seems to still happen in Android PhoneGap apps. – Rob Porter Apr 10 '13 at 15:06
  • For a reliable user experience, use the new clickableIcons property in MapOptions (see xomena's answer below) – miguev Jun 13 '16 at 07:50
8

Found a workaround! It's pretty dirty so it might stop work if google changes something, but it works!

You have to find the layers where google puts the infoWindows for POIs. Fortunatelly these layers are different from the layers used for users infoWindows. The trick is to find the proper layers. The shadow layer can be found easily, but the infoWindow layer is created after some POI infoWindow is created, so you have to listener to the click event on the same div as google does. Then you find the POI infoWindow layer by z-index, or by image urls but this is not well tested... Note that if google changes the z-index, it will stop work...

var lis = google.maps.event.addListener(my_map, 'tilesloaded', function () {

    $('*').filter(function () { return $(this).css('z-index') == 104 }).remove();
        // remove layer for POI infoWindow shadow - has z-index: 104

    var eventDiv = $(my_map.getDiv()).children().children()[0];
        // this div is used by google to handle events

    $(eventDiv).click(function clickHandler() {
        var timeout = 100;
        var attempts = 20;
        setTimeout(function timeoutHandler() {
            // there are 2 ways how to find POI infoWindow layer
            // 1st way - by the z-index
            var poiInfoLayer = $('*').filter(function () { 
                return $(this).css('z-index') == 169 || 
                       $(this).css('z-index') == 248 
            });
            // 2nd way - by the images :-)
            // but not tested much - it may also find normal infoWindows!
            //var poiInfoLayer = $('[src*="/mapfiles/iw3.png"]').parent().parent();

            if (poiInfoLayer.length) {
                    poiInfoLayer.remove();
                    $(eventDiv).unbind('click', clickHandler);
            }
            else {
                    if (attempts > 0) {
                            setTimeout(timeoutHandler, timeout);
                            attempts--;
                    }
            }

        }, timeout);
    });
    google.maps.event.removeListener(lis);
});
Tomas
  • 57,621
  • 49
  • 238
  • 373
  • 2
    please explain the downvotes. It took me few hours to make this out! – Tomas Dec 08 '11 at 08:57
  • I liked it and upvoted - but people, you have to know this is like removing paid ads in a web page. Unlike a browser plugin that does this, google could just blacklist your domain if you have enough traffic. – tim Jul 13 '12 at 01:52
  • This didn't work for me. That's normal since it was written 3 years ago. I found another workaround, posted here: http://stackoverflow.com/a/24817995/943535 – Nail Jul 18 '14 at 05:58
  • 1
    For a reliable user experience, use the new clickableIcons property in MapOptions (see xomena's answer below) – miguev Jun 13 '16 at 07:51
5

Edit: Ok, looks like Google implemented a solution, look at xomena answer.

Ok, after searching everywhere it looks like you can't just display the POIs with clicking disabled, you could look here for more discussions:

http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/f1ac9ad4da3606fe/3975bbda46904ae7?lnk=gst&q=disable+poi#3975bbda46904ae7

and this exchange in particular:


Hi,

Is there any possibilltiy to make POIs visible but not clickable?

Thanks Lorenzo


Chris Broadfoot

Unfortunately not Lorenzo. You'll need to apply a map style to hide poi labels:

[ { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] } ]

(or to just hide business pois, "poi.business")


This comes from Google Maps developers, so means you can't disable the popup, just the POIs.

Roman Goyenko
  • 6,965
  • 5
  • 48
  • 81
  • 1
    Did you even run your own code? I did and you click the airport icon and get an infowindow – Andrew G. Johnson Nov 10 '11 at 06:16
  • 4
    Of course I did. So, your goal is to not display the bubble when clicked? I thought you got the bubble automatically when just displaying the map. Let me look into it. And giving -1 for people trying to help you and spending hours doing it is not cool, by the way. – Roman Goyenko Nov 10 '11 at 14:54
  • 3
    I didn't downvote your effort I downvoted an answer that ignored my question – Andrew G. Johnson Nov 11 '11 at 08:55
  • 1
    @Romario, the second block beginning with "Chris Broadfoot ..." just repeats the code the OP has in his question. – Tomas Dec 02 '11 at 15:25
  • For a reliable user experience, use the new clickableIcons property in MapOptions (see xomena's answer below) – miguev Jun 13 '16 at 07:50
2

I would inspect element using firebug and use display:none !important; to remove these styles if Google does not allow you to access them directly via the API (which I would think you should be able to)

jeffreynolte
  • 3,749
  • 11
  • 41
  • 64
  • I may be using custom bubbles so that may not work for me. Also I suspect there's a way to disable them [sounds like you do too] just can't find any great details about this in the Google documentation – Andrew G. Johnson Oct 31 '11 at 04:36
  • are there no styles associated with the custom bubbles, when limited with options in the past from the Gmap API I just went with an option of removing unwanted elements with CSS. – jeffreynolte Oct 31 '11 at 04:37
  • The API allows you to add your own bubbles with your own data in them if you like. I'm saying I may use that functionality so disabling all bubbles may not be an option for me. – Andrew G. Johnson Oct 31 '11 at 04:39
  • I was examining this possibility and **it is a dead end**. The POIs not done using DOM (no divs, no html map areas ...). The POI clickable areas must be somehow handled just with javascript, probably just with handling the map click event. So it would be hard to impossible to try to hack it this way. – Tomas Dec 02 '11 at 15:21
0

Right, to sum up, if you want to "remove" popups, you can just use:

clickableIcons: false

for map options object. But if you want to have a popup, but without "View on Google Maps" label, you can use a hacky CSS trick:

google-map {
  .view-link {
    display: none !important;
  }
}

That was my requirements, and it works!

If you want to define which icons/pins (elements or labels, however you call it) should be visible, you can use this site to generate proper JSON with map settings: https://mapstyle.withgoogle.com/

divisible
  • 31
  • 1
  • 7
-3

Suggest you look at the answer I gave here: How do I remove default markers?

var myStyles =[
    {
        featureType: "poi",
        elementType: "labels",
        stylers: [
              { visibility: "off" }
        ]
    }
];

var myOptions = {
    zoom: 10,
    center: homeLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    styles: myStyles 
};
Community
  • 1
  • 1
duncan
  • 31,401
  • 13
  • 78
  • 99