1

我正在尝试更改地图的大小并保持中心。这行不通。代码

var center = map.getCenter()
$('#left').css("width", "360px");
map.setCenter(center)
4

1 回答 1

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);
于 2012-06-16T14:02:26.453 回答