I have need to change width and height of google maps infoWindow and I saw this topic Google Map .InfoWindow Set Height and Width. I found that the solutions from it doesn't work. Even standart infoWindow = new google.maps.InfoWindow({maxWidth: '50px'})
isn't going to work.
So what is a solution? How to change width and height of infoWindow?
This works for me:
new google.maps.InfoWindow({ maxWidth: 320 });
Remove the ' ' and the px specifier and I believe it will work for you too.
I always use a div inside the infowindow and it works best for me. Then you just set the size of the div via css.
Here is a link. :
Google Maps API v3: InfoWindow not sizing correctly
The GoogleMaps-API generates the class "gm-style-iw
" around the InfoWindow
. So you can simply change the size by CSS, without the need of extra markup:
var infowindow = new google.maps.InfoWindow({
content: contentString
});
.gm-style-iw {
height: 100px;
width: 300px;
}
I have added and it is working
var infowindow = new google.maps.InfoWindow({
content:'<div style="width:200px; height:100px">Some text</div>'
});
infowindow = new google.maps.InfoWindow({
content: "",
maxWidth: 200 ,
maxHeight: 400
});
I found that unless I forced the style with !important
, it didn't work. So:
.gm-style-iw {
height: 100px;
width: 300px !important;
}
I know this is an old question but I would like to add a responsive solution. This will adapt nicely on small devices.
@media (max-width: 413px) {
// Set gm container to screen width leaving 20px pad on each side
.gm-style-iw {
width: calc(100vw - 40px)!important;
min-width: unset!important;
max-width: unset!important;
}
// Next is the container Div that you create on your infoWindow function
// on google example var contentString = '<div id="content">'+
.your-main-container-class {
width: calc(100vw - 80px);
padding: 8px 0;
margin: auto;
}
}
Then for bigger screens just set your width as google suggest
.your-main-container-class{
width: 316px; // Your desire width
padding: 8px 0 8px 8px; // Play with padding if you have a custom close button
}