开发者

How do setBounds in Google Maps API v2?

开发者 https://www.devze.com 2022-12-30 11:14 出处:网络
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'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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消