kbhot
02-26-2012, 11:08 PM
I am trying to place a different google map in each tabbed of a spry tabbed panel. There is a known issue with google map V3 where the map will function properly on the default tab, but when the hidden tabs are unhidden, the map on those previously hidden tabs has centred in the very top left of the container div and only fills a small part of the container.
( www.kimholt.co.uk/locations demonstrates this, the London tab is fine, but the South West tab doesn't work properly).
I have spent hours on this bug so far, and tried many fixes. The only one that has got me anywhere so far is adding
[CODE]
google.maps.event.addListener(map, "idle", function() {google.maps.event.trigger(map, 'resize'); });
after var map = new google.maps.Map(document.getElementById(canvas), myOptions);
[CODE]
This doesn't resize the map automatically, but will resize it if the map is dragged slightly by the user. It also still has the marker centred in the top left of the screen rather than the centre of the canvas. The following solutions have also been suggested:
Re-centrering the map around the marker
[CODE]
google.maps.event.trigger({map}, 'resize'); {map}.setCenter({marker}.getPosition());
[CODE]
Zooming in and out again to trigger the resize:
[CODE]
map.setZoom( map.getZoom() );
[CODE]
Or using this to do the same thing:
[CODE]
this.map.setZoom( this.map.getZoom() - 1); this.map.setZoom( this.map.getZoom() + 1);
[CODE]
Suggested for use if there are multiple markers:
[CODE]
map.setZoom(map.getZoom()); map.fitBounds(bounds);
[CODE]
I haven't been able to get any of these to work, but I'm not sure if I am using them in the right place in the javascript, and I'm also not sure if there are any parts of this code that need amending to make them work in my particular code. How can I get the map to automatically resize when the tab is selected? How can I get the map to automatically recentre around the marker when the map is opened? Being fairly new to this I really need someone to look at my actual code and help me work out exactly what to put where, in other words assume I know nothing and will be extremely grateful for any help!
( www.kimholt.co.uk/locations demonstrates this, the London tab is fine, but the South West tab doesn't work properly).
I have spent hours on this bug so far, and tried many fixes. The only one that has got me anywhere so far is adding
[CODE]
google.maps.event.addListener(map, "idle", function() {google.maps.event.trigger(map, 'resize'); });
after var map = new google.maps.Map(document.getElementById(canvas), myOptions);
[CODE]
This doesn't resize the map automatically, but will resize it if the map is dragged slightly by the user. It also still has the marker centred in the top left of the screen rather than the centre of the canvas. The following solutions have also been suggested:
Re-centrering the map around the marker
[CODE]
google.maps.event.trigger({map}, 'resize'); {map}.setCenter({marker}.getPosition());
[CODE]
Zooming in and out again to trigger the resize:
[CODE]
map.setZoom( map.getZoom() );
[CODE]
Or using this to do the same thing:
[CODE]
this.map.setZoom( this.map.getZoom() - 1); this.map.setZoom( this.map.getZoom() + 1);
[CODE]
Suggested for use if there are multiple markers:
[CODE]
map.setZoom(map.getZoom()); map.fitBounds(bounds);
[CODE]
I haven't been able to get any of these to work, but I'm not sure if I am using them in the right place in the javascript, and I'm also not sure if there are any parts of this code that need amending to make them work in my particular code. How can I get the map to automatically resize when the tab is selected? How can I get the map to automatically recentre around the marker when the map is opened? Being fairly new to this I really need someone to look at my actual code and help me work out exactly what to put where, in other words assume I know nothing and will be extremely grateful for any help!