2016-10-19 51 views
0

在我的地圖,我想用ScaleGestureDetector捕捉/放大,但我從來沒有接收任何回調至任一onScaleonScaleBeginonScaleEnd谷歌手機地圖的兩個手指捏/拉伸回調

在我的片段的onCreateView,我初始化:

scaleGestureDetector = new ScaleGestureDetector(getContext(), new simpleOnScaleGestureListener());

我實現像這樣的回調:

public class simpleOnScaleGestureListener extends 
     SimpleOnScaleGestureListener { 

    @Override 
    public boolean onScale(ScaleGestureDetector detector) { 
     // TODO Auto-generated method stub 
     startScale = detector.getScaleFactor(); 
     Log.d(TAG, "::onScale:: " + detector.getScaleFactor()); 
     return true; 
    } 

    @Override 
    public boolean onScaleBegin(ScaleGestureDetector detector) { 
     // TODO Auto-generated method stub 
     Log.d(TAG, "::onScaleBegin:: " + detector.getScaleFactor()); 
     return true; 
    } 

    @Override 
    public void onScaleEnd(ScaleGestureDetector detector) { 
     // TODO Auto-generated method stub 
     Log.d(TAG, "::onScaleEnd:: " + detector.getScaleFactor()); 
     endScale = detector.getScaleFactor(); 

} 

而且,是不是可以認爲回調將不斷呼籲每當用戶放大/縮小?

回答

0

我能夠通過獲取回調的問題。從本質上講,兩件事情:

  1. 在您的活動/片段,實施GoogleMap.OnCameraIdleListener
  2. onMapReady()call mMap.setOnCameraIdleListener(this);
  3. 因此,覆蓋onCameraIdle()

@Override public void onCameraIdle() { Log.i(TAG, "::onCameraIdle::" + mMap.getCameraPosition().toString()); }

得到緯度/長,放大,傾斜和軸承,基本上CameraPosition

我找到了一種方法參照本response

VisibleRegion vr = map.getProjection().getVisibleRegion(); 

Location center = new Location("center"); 
center.setLatitude(vr.latLngBounds.getCenter().latitude); 
center.setLongitude(vr.latLngBounds.getCenter().longitude); 

//Location("radiusLatLng") as mentioned in google maps sample 
Location farVisiblePoint = new Location("radiusLatLng"); 
farVisiblePoint.setLatitude(vr.farLeft.latitude); 
farVisiblePoint.setLongitude(vr.farLeft.longitude); 

radius = center.distanceTo(farVisiblePoint); 
得到米半徑