13

I'm facing the problem,My google Map API showing default InfoWindow with background color white.I want change the White color to Black color. REF CODE:

google.maps.event.addListener(marker, 'mouseover', function() {


    infoWindow.setContent(html);
        infoWindow.open(map, marker);
               //infoWindow.setStyle("background-color: red");


      });

3 Answers3

12

I came up with a simple solution. This might not be a very elegant solution but it works fine if you don't have huge styling needs.

Since we can add our own html and style it. The marker background element is mainly the one which causes problem. For simple styling, instead of learning a whole new library, we can just remove that element using jQuery.

Insert this code in your init function and it will remove the background element.

google.maps.event.addListenerOnce(map, 'idle', function(){
    jQuery('.gm-style-iw').prev('div').remove();
}); 

Now, you are free to style your own divs. I styled the infoWindow in my project using this approach. enter image description here

Hope it will help.

Awais Umar
  • 2,027
  • 3
  • 27
  • 46
8

This works for me :

.gm-style .gm-style-iw-d::-webkit-scrollbar-track, 
.gm-style .gm-style-iw-d::-webkit-scrollbar-track-piece,
.gm-style .gm-style-iw-c,
.gm-style .gm-style-iw-t::after { 
  background: red;
}
Radon8472
  • 4,285
  • 1
  • 33
  • 41
Andrew Forbes
  • 81
  • 1
  • 4
  • Good, but there is still a reverse triangular in white at the bottom of infoWindow. So I also add the following .gm-style .gm-style-iw-tc::after { background: red; } – Yigit Pilevne Sep 09 '22 at 12:49
  • 1
    Also add the following `.gm-style .gm-style-iw-tc::after { background: red; }` – Lee Taylor Sep 24 '22 at 14:27
3

You can use the InfoBox here in Google Maps Utility.

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

You can also use CSS to style it. By checking this tutorial and this, it will give you a sample code on how to do it.

KENdi
  • 7,576
  • 2
  • 16
  • 31
  • 3
    The first link is broken, probably InfoBox [has been removed](http://stackoverflow.com/questions/37171426/google-maps-api-v3-infobox-js-removed). – T30 Nov 29 '16 at 14:50