javascript - How to use map.getCenter() and google.maps.event.trigger() -


i'm using gmap module. if try initialise map on hidden div, fail display.

we can use google.maps.event.trigger(map, 'resize'); in script, because got map on top left corner.

i found solution map.getcenter(); map.setcenter(); when use in js file inside tabs custom code, doesn't work, because "map" not defined.

is there solution this?

here's code:

$(document).ready(function(){          $('.spoiler-body1').hide();          $('.spoiler-head').click(function(){              var mapobj = window[$('.bx-google-map').attr('id')];             var center = mapobj.getcenter();              $(this).toggleclass("folded1").toggleclass("unfolded").next().slidetoggle();              google.maps.event.trigger(mapobj, 'resize');              mapobj.setcenter(center);         });     }); 

i presume have map initialize on separate window.onload (or equivalent). script needs run after map initialization. happening this window.onload runs before other 1 initialization script, though technically fire @ same time.

this can fixed appending script map initialization directly. guarantee timing lines up.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -