Google Maps: How to create a custom InfoWindow?

Google Maps: How to create a custom InfoWindow?

The default Google Maps InfoWindow for a map marker is very round. How do I create a custom InfoWindow with square corners?


Solution 1:

EDIT After some hunting around, this seems to be the best option:

You can see a customised version of this InfoBubble that I used on Dive Seven, a website for online scuba dive logging. It looks like this:

Google provide a demo that shows how to implement a custom info window. It requires a fair amount of code, but seems to be pretty straightforward.

There are some more examples here. They definitely don’t look as nice as the example in your screenshot, however.

Solution 2:

You can modify the whole InfoWindow using jquery alone…

var popup = new google.maps.InfoWindow({
    content:'<p id="hook">Hello World!</p>'

Here the <p> element will act as a hook into the actual InfoWindow. Once the domready fires, the element will become active and accessible using javascript/jquery, like $('#hook').parent().parent().parent().parent().

The below code just sets a 2 pixel border around the InfoWindow.

google.maps.event.addListener(popup, 'domready', function() {
    var l = $('#hook').parent().parent().parent().siblings();
    for (var i = 0; i < l.length; i++) {
        if($(l[i]).css('z-index') == 'auto') {
            $(l[i]).css('border-radius', '16px 16px 16px 16px');
            $(l[i]).css('border', '2px solid red');

You can do anything like setting a new CSS class or just adding a new element.

Play around with the elements to get what you need…

Solution 3:

I found InfoBox perfect for advanced styling.

An InfoBox behaves like a google.maps.InfoWindow, but it
supports several additional properties for advanced styling. An
InfoBox can also be used as a map label. An InfoBox also fires the
same events as a google.maps.InfoWindow.

Include in your page

Solution 4:

Styling the infowindow is fairly straightforward with vanilla javascript. I used some of the info from this thread when writing this. I also took into account the possible problems with earlier versions of ie (although I have not tested it with them).

var infowindow = new google.maps.InfoWindow({
  content: '<div id="gm_content">'+contentString+'</div>'

  var el = document.getElementById('gm_content').parentNode.parentNode.parentNode;
  el.firstChild.setAttribute('title','Close Info Window');
  el = (el.previousElementSibling)?el.previousElementSibling:el.previousSibling;
  for(var i=0; i<11; i++){
    el = (el.previousElementSibling)?el.previousElementSibling:el.previousSibling; = 'none';

The code creates the infowindow as usual (no need for plugins, custom overlays or huge code), using a div with an id to hold the content. This gives a hook in the system that we can use to get the correct elements to manipulate with a simple external stylesheet.

There are a couple of extra pieces (that are not strictly needed) which handle things like giving a hook into the div with the close info window image in it.

The final loop hides all the pieces of the pointer arrow. I needed this myself as I wanted to have transparency on the infowindow and the arrow got in the way. Of course, with the hook, changing the code to replace the arrow image with a png of your choice should be fairly simple too.

If you want to change it to jquery (no idea why you would) then that should be fairly simple.

I’m not usually a javascript developer so any thoughts, comments, criticisms welcome 🙂

Solution 5:

Below piece of code may help you out.

var infowindow = new google.maps.InfoWindow();
 google.maps.event.addListener(marker, 'mouseover', (function(marker) {
            return function() {
                var content = address;
      , marker);

Here is an article < How to locate multiple addresses on google maps with perfect zoom > that helped me achieved this. You can refer it for working JS Fiddle link and complete example.

Solution 6:

I’m not sure how is doing it specifically, but I’d wager they are using Custom Overlays.