Android的GMaps实现V2:边界和最大缩放级别 [英] android Gmaps v2 : Bounds and max zoom level

查看:339
本文介绍了Android的GMaps实现V2:边界和最大缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于Android和谷歌地图V2。我想设定范围最大缩放级别。
下面是我使用的方法:

it is about android and google maps v2. I want to set max zoom level with bounds. Here is the method I'm using :

gMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));

我发现这个链接,给了我一个可能的解决方法
<一href=\"http://stackoverflow.com/questions/15700808/setting-max-zoom-level-in-google-maps-android-api-v2\">Setting在谷歌最大缩放级别的Andr​​oid地图API V2

下面是workaraound发现

Here is the workaraound found

gMap.setOnCameraChangeListener(new OnCameraChangeListener() {
    @Override
    public void onCameraChange(CameraPosition position) {
        if (position.zoom > DEFAULT_ZOOM)
            gMap.animateCamera(CameraUpdateFactory.zoomTo(DEFAULT_ZOOM));
    }
});

但直到缩放级别该解决方案变焦首先 animateCamera ,然后定义缩小,直到DEFAULT_ZOOM如果(DEFAULT_ZOOM&LT; position.zoom)。在这种情况下,有两个 animateCamera

But this solution zoom in until the zoom level defined by first animateCamera and then zoom out until DEFAULT_ZOOM if (DEFAULT_ZOOM < position.zoom). In this case, there is two animateCamera

如何避免呢?并只有一个 animateCamera

How to avoid that ? And make only one animateCamera

Thx提前

推荐答案

好了,现在,我唯一的解决办法是在这里与<一个href=\"http://stackoverflow.com/a/19343818/1646479\">http://stackoverflow.com/a/19343818/1646479

Ok, for now, my only solution is related here http://stackoverflow.com/a/19343818/1646479

下面是解决方法:

private LatLngBounds adjustBoundsForMaxZoomLevel(LatLngBounds bounds) {
  LatLng sw = bounds.southwest;
  LatLng ne = bounds.northeast;
  double deltaLat = Math.abs(sw.latitude - ne.latitude);
  double deltaLon = Math.abs(sw.longitude - ne.longitude);

  final double zoomN = 0.005; // minimum zoom coefficient
  if (deltaLat < zoomN) {
     sw = new LatLng(sw.latitude - (zoomN - deltaLat / 2), sw.longitude);
     ne = new LatLng(ne.latitude + (zoomN - deltaLat / 2), ne.longitude);
     bounds = new LatLngBounds(sw, ne);
  }
  else if (deltaLon < zoomN) {
     sw = new LatLng(sw.latitude, sw.longitude - (zoomN - deltaLon / 2));
     ne = new LatLng(ne.latitude, ne.longitude + (zoomN - deltaLon / 2));
     bounds = new LatLngBounds(sw, ne);
  }

  return bounds;
}

但我正在寻找一个解决方案,(在我的案件16)翻译Android缩放级别 zoomN

这篇关于Android的GMaps实现V2:边界和最大缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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