Java Google Maps V2 - Android - 获取当前缩放级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16366484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Maps V2 - Android - Get the current zoom level
提问by user268397
How do I get the current zoom level as an integer on a GoogleMap. I need to take this code from GMaps v1.1:
如何在 GoogleMap 上以整数形式获取当前缩放级别。我需要从 GMaps v1.1 中获取此代码:
MapView mGoogleMapView;
int zoomLevel = mGoogleMapView.getZoomLevel();
I am aware of the methods getMinZoomLevel() and getMaxZoomLevel() however I can't find anything in the Android GMap V2 documentation that will give the current zoom level. Does anyone have any pointers on how to do this?
我知道 getMinZoomLevel() 和 getMaxZoomLevel() 方法,但是我在 Android GMap V2 文档中找不到任何可以提供当前缩放级别的内容。有没有人对如何做到这一点有任何指示?
Any help would be appreciated.
任何帮助,将不胜感激。
采纳答案by Pavel Dudka
GoogleMap map;
....
....
float zoom = map.getCameraPosition().zoom;
回答by CommonsWare
Call getCameraPosition()
on the GoogleMap
, and read the zoom
field of the resulting CameraPosition
object.
打电话getCameraPosition()
的GoogleMap
,并读取zoom
所产生的领域CameraPosition
对象。
回答by ridoy
I think OnCameraChangeListenerwill do the trick..
我认为OnCameraChangeListener会做到这一点..
map.setOnCameraChangeListener(new OnCameraChangeListener() {
private float currentZoom = -1;
@Override
public void onCameraChange(CameraPosition position) {
if (position.zoom != currentZoom){
currentZoom = position.zoom; // here you get zoom level
}
}
});
Update:
更新:
From Google Play service 9.4.0 OnCameraChangeListenerhas been deprecated and it will no longer work soon.Alternately they are replaced by OnCameraMoveStarted??Listener,OnCameraMoveListener,OnCameraMoveCancel??edListenerand OnCameraIdleListener.
从 Google Play 服务 9.4.0 OnCameraChangeListener已被弃用,它很快将不再工作。或者它们被OnCameraMoveStarted??Listener、OnCameraMoveListener、OnCameraMoveCancel??edListener和OnCameraIdleListener 取代。
Hence we can use OnCameraIdleListenerhere to get camera's current zoom level.
因此我们可以在这里使用OnCameraIdleListener来获取相机的当前缩放级别。
Code Sample:
代码示例:
map.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
@Override
public void onCameraIdle() {
int zoomLevel = map.getCameraPosition().zoom;
//use zoomLevel value..
}
});