0

In my map, I am trying to capture zoom in/out using ScaleGestureDetector but I am never receiving any callbacks to either of onScale or onScaleBegin or onScaleEnd.

In my Fragment's onCreateView, I initialize:

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

And I implement the callbacks like so:

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();

}

Also, is it fair to assume that the callbacks will be called continuously whenever the user zooms in/out?

Anil Gorthy
  • 869
  • 3
  • 13
  • 30

1 Answers1

0

I was able to get past the issue of getting callbacks. Essentially, two things:

  1. In your activity/fragment, implement, GoogleMap.OnCameraIdleListener
  2. In onMapReady(), call mMap.setOnCameraIdleListener(this);
  3. Hence, override onCameraIdle():

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

to get lat/long, zoom, tilt and bearing, essentially CameraPosition.

I found a way to get radius in meters by referring to this 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);
Community
  • 1
  • 1
Anil Gorthy
  • 869
  • 3
  • 13
  • 30