在我的地图中,我尝试使用ScaleGestureDetector
捕捉放大/缩小,但我从不接收onScale
或onScaleBegin
的任何回调或onScaleEnd
。
在我的片段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 :(得分:0)
我能够解决获得回调的问题。基本上,有两件事:
GoogleMap.OnCameraIdleListener
onMapReady()
,call mMap.setOnCameraIdleListener(this);
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);