i have a page and a google map is inside a hidden div at first. I then show the div after i click a link but only the top left of the map shows up.
i tried having this code run after the click:
map0.onResize();
or:
google.maps.event.trigger(map0, 'resize')
any ideas. here is an image of what i see after showing the div with the hidden map in it.
Just tested it myself and here's how I approached it. Pretty straight forward, let me know if you need any clarification
HTML
CSS
Javascript
If you have a Google Map inserted by copy/pasting the iframe code and you don't want to use Google Maps API, this is an easy solution. Just execute the following javascript line when you show the hidden map. It just takes the iframe HTML code and insert it in the same place, so it renders again:
jQuery version:
The HTML:
The following example works for a map initially hidden in a Bootstrap 3 tab:
First post. My googleMap div was within a container div with {display:none} until tab clicked. Had the same problem as OP. This worked for me:
Stick this code inside and at the end of your code where your container div tab is clicked and reveals your hidden div. The important thing is that your container div has to be visible before initialize can be called.
I tried a number of solutions proposed here and other pages and they didn't work for me. Let me know if this works for you. Thanks.
My solution is very simple and efficient:
HTML
CSS
Jquery
I didn't like that the map would load only after the hidden div had become visible. In a carousel, for example, that doesn't really work.
This my solution is to add class to the hidden element to unhide it and hide it with position absolute instead, then render the map, and remove the class after map load.
Tested in Bootstrap Carousel.
HTML
<div class="item loading"><div id="map-canvas"></div></div>
CSS
JS