1

I'm trying to change the size of a map and maintain the center. It doesn't work thoug. Code

var center = map.getCenter()
$('#left').css("width", "360px");
map.setCenter(center)
Pointy
  • 405,095
  • 59
  • 585
  • 614
Himmators
  • 14,278
  • 36
  • 132
  • 223

1 Answers1

1

Have a look at the accepted answer in this question: How to offset the center point in Google maps api V3

What you need to do is work out how far the centre-point of the map will need to be moved so it's where it was before the re-size, and then call my new offsetCenter function to put it back there.

For example: resizing a map so that the left edge moves 300px to the left will require your centre-point to appear 150px to the right of the real centre.

var center = map.getCenter();
$('#left').css("width", "360px");
google.maps.event.trigger(map, 'resize');
offsetCenter(center,150,0);
Community
  • 1
  • 1
Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
  • 1
    Hrm, I was playing around with your function and it seems to do what I want if I pass offsetCenter(center,0,0); – Himmators Jun 16 '12 at 14:22