问题描述
这是关于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));
我发现这个链接,给了我一个可能的解决方法
Setting在谷歌最大缩放级别的Android地图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< 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提前
推荐答案
好了,现在,我唯一的解决办法是在这里与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:边界和最大缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!