map resize only possible after timeout?

87 views
Skip to first unread message

faeb187

unread,
Dec 12, 2011, 12:10:36 PM12/12/11
to google-map...@googlegroups.com
when I navigate to the map on my webapp, the 'map container div' gets display:block (so div size changed).
this means I have to resize the map and set the center of the map again...

the problem is, that this only works when I set a little timeout...
(yes, my div is visible before I execute this code...)

setTimeout( function(){
google.maps.event.trigger( detMap, "resize" );
detMap.setCenter( p.latLng );
}, 20 );

I think there must be a better way to do this???
Is there a workaround?

thx faeb187

Chad Killingsworth

unread,
Dec 12, 2011, 3:32:08 PM12/12/11
to google-map...@googlegroups.com
Have you tried something like:

google.maps.event.addListenerOnce(detMap, "resize", function() {
  detMap.setCenter( p.latLng );
});
google.maps.event.trigger(detMap, "resize");
Reply all
Reply to author
Forward
0 new messages