This does not answer all your questions, but I got his job, and all the other answers miss one thing: when you redraw the map with the "resize" event, you will lose the place where the map was in the center. Therefore, you also need to update the center of the map with setCenter if your map is focused on the position.
In addition, you do not want to initialize the card each time you start a tab, because it is inefficient and can lead to additional geocodes. Firstly, you need to maintain its centered position, which can be static lat / long or geocoding, might look something like this:
var address = "21 Jump St, New York, NY"; var geocoder = new google.maps.Geocoder(); var myOptions = { zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var center; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { center = results[0].geometry.location; map.setCenter(center); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert("Geocode was not successful for the following reason: " + status); } });
Then
$("#tabs").tabs(); $('#tabs').bind('tabsshow', function(event, ui) { if (ui.panel.id == "mapTab") { google.maps.event.trigger(map, "resize"); map.setCenter(center); bind ( 'tabsshow', function (event, ui) { $("#tabs").tabs(); $('#tabs').bind('tabsshow', function(event, ui) { if (ui.panel.id == "mapTab") { google.maps.event.trigger(map, "resize"); map.setCenter(center);
Where "mapTab" is the identifier of your mapTab, and "map" is the var name for your map object.
paul Jun 04 '12 at 23:01 2012-06-04 23:01
source share