Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Google map's marker's infowindow max height?

If the contents of the info window of marker is too long, it won't fit into the window, it will overflow at the bottom. How can I fix this?

like image 483
egaga Avatar asked May 28 '09 07:05

egaga


People also ask

How do I put infowindow on marker?

Move an info windowAttach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.

How do I show multiple Infowindows on Google Maps?

By assigning the infowindow to a marker property, each marker can have it's own infowindow. This was how I approached the problem, with the relevant sample code. //create a marker object first, or instantiate it by passing a JSON to the constructor. //this can be done inside a for loop var infowindow = new google.


1 Answers

The accepted answer is a bit vague...

So here's a couple of direct solutions for anyone looking to change the height of InfoWindows, or other style properties.

Method 1: CSS

Apply a CSS rule like so. It changes all infowindow's:

.gm-style-iw {
    max-height: 200px !important;
    overflow: auto !important;
}

Or, if you have custom IW templates, this can work too:

#myInfoWindow-content {
    max-height: 200px !important;
    overflow: auto !important;
}

Overflow needs to have !important, otherwise it gets superseded by GM's own rules and long content could be cut-off. Max-height will work without !important, but probably better to keep it anyways.

Method 2: Inline CSS

If you use templates for IW content, then an option is to hardcode styles inline per infowindow.

<div id="myInfoWindow-content" style="max-height: 150px; overflow: auto;">
  content
</div>

Method 3: Javascript

You can always use JS to modify things dynamically. You can use this method to target and modify other IW elements, like hiding IW arrows.

document.getElementById('myInfoWindow-content').style.maxHeight = '20px';
document.getElementById('myInfoWindow-content').style.overflow = 'auto';
like image 157
MarsAndBack Avatar answered Sep 29 '22 20:09

MarsAndBack