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.
I had the same issue, the
google.maps.event.trigger(map, 'resize')
wasn't working for me.What I did was to put a timer to update the map after putting visible the
div
...I don't know if it's the more convenient way to do it but it works!
How to refresh the map when you resize your div
It's not enough just to call
google.maps.event.trigger(map, 'resize');
You should reset the center of the map as well.How to listen for the resize event
Angular (ng-show or ui-bootstrap collapse)
Bind directly to the element's visibility rather than to the value bound to ng-show, because the $watch can fire before the ng-show is updated (so the div will still be invisible).
jQuery .show()
Use the built in callback
Bootstrap 3 Modal
It's also possible to just trigger the native window resize event.
Google Maps will reload itself automatically:
With jQuery you could do something like this. This helped me load a Google Map in Umbraco CMS on a tab that would not be visible from right away.
I guess the original question is with a map that is initalized in a hidden div of the page. I solved a similar problem by resizing the map in the hidden div upon document ready, after it is initialized, regardless of its display status. In my case, I have 2 maps, one is shown and one is hidden when they are initialized and I don't want to initial a map every time it is shown. It is an old post, but I hope it helps anyone who are looking.
Or if you use gmaps.js, call:
when your div is shown.