I use GoMap jQuery plugin for Google map. The div with the map is hidden by default. I almost figured how to display the map correctly, but somehow I’m unable to center the map after I reveal the div. I tried every solution I was able to find, right now I have the code below, which still doesn’t work right. Anyone could help me with this? Thanks.
<h3><a class="showmap" href="#">Show map</a></h3>
<div id="map" style="height: 350px; width: 700px;"> </div>
<script type="text/javascript">
$(function() {
$("#map").goMap({
markers: [{
latitude: 49.676196,
longitude: 13.444927,
html: {
content: 'Marker description',
popup: true
}
}],
hideByClick: false,
zoom: 12
});
});
$(document).ready(function(){
$("#map").hide();
});
$('.showmap').click(function(){
$('#map').slideToggle('slow', function() {
var center = $.goMap.map.getCenter();
google.maps.event.trigger($.goMap.map, 'resize');
$.goMap.map.setCenter(center);
});
});
Your solution is almost perfect, but by default the map will pan to make the infoWindow visible, what will change the center.
You may disable the AutoPan: