Google Maps API v2中的setBounds如何? [英] How do setBounds in Google Maps API v2?

查看:115
本文介绍了Google Maps API v2中的setBounds如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在升级为Google Maps API v2编写的一些代码,并且希望设置地图的边界(顶部,左侧,底部,右侧),而不是中心。

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.

我注意到有一个 GMap2.getBounds ,但我似乎无法找到一种方法,允许我设置边界。

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

如何在Google Maps中执行此操作?

How can I do this in Google Maps?

推荐答案

找到在这里做一个setBounds的方法: http:/ /www.mymapofjapan.com/blog/setting-size-and-zoom-level-of-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));

由于Google地图具有不连续的缩放级别,因此您可能无法将其设置为完全界限你想要的,所以你可能需要调用map.getBounds();之后向用户展示他们正在查看的实际边界。

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.

这篇关于Google Maps API v2中的setBounds如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆