views:

160

answers:

1

I'm upgrading some code written for Google Maps API v2, and I wish to set the bounds of the map (top, left, bottom, right), rather than the centre.

I notice that there's a GMap2.getBounds but I can't seem to find a method which allows me to set the bounds.

How can I do this in Google Maps?

+2  A: 

Found a way to do a setBounds here: http://www.mymapofjapan.com/blog/setting-size-and-zoom-level-of-maps/

var bounds = new GLatLngBounds; 
bounds.extend(new GLatLng( South, West )); 
bounds.extend(new GLatLng( North, East )); 
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

Because Google Maps has discrete zoom levels you probably won't be able to set it to exactly the bounds you wanted, so you might need to call map.getBounds(); afterwards to show the user the actual bounds they are looking at.

Matthew Lock