Double-click / tap map zoom (Android)

Possible duplicate:
Double Tap β†’ Zoom on Android MapView?

I have Activityone that expands MapActivity. I use Google Maps.
I need to enlarge the image by double-clicking or double-clicking.

Can someone help me?

I already looked below, but they are not what I am looking for.

Double Tap β†’ Zoom on Android MapView?

Gesture recognition when placing a grid

I realized that it onTouchListeneris called only once, why is this so?

// set Gesture
detector = new GestureDetector(new GestureReactor());
mapView.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        System.out.println("Inside onTouch");
        return detector.onTouchEvent(event);
    }
});

I have a private class:

private class GestureReactor extends SimpleOnGestureListener {
    @Override
    public boolean onDoubleTap(MotionEvent e) {
        System.out.println("inside onDouble");
        controller.zoomInFixing((int) e.getX(), (int) e.getY());
        return super.onDoubleTap(e);
    }
}

and

private GestureDetector detector;
+5
source share
6 answers

"-", .

EDIT:

public class MainMap extends MapActivity private MyMapView mv;

, MapView : public class MyMapView extends MapView.

, , extends MapView, , , class , extends MapActivity.

+3

, MapView . MapView , voodoo. , .

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

import com.google.android.maps.MapView;

public class MyMapView extends MapView {
    private long lastTouchTime = -1;

    public MyMapView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            long thisTime = System.currentTimeMillis();
            if (thisTime - lastTouchTime < ViewConfiguration.getDoubleTapTimeout()) {
                // Double tap
                this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
                lastTouchTime = -1;
            } else {
                // Too slow :)
                lastTouchTime = thisTime;
            }
        }

        return super.onInterceptTouchEvent(ev);
    }
}

+3

, bbodenmiller, , . mapView = (MyMapView) findViewById (R.id.mapview); .

, XML, MapView. MapView, XML- :

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="Hidden for obvious reasons"
/>

, "com.google.android.maps.MapView" MapView. MapView. .

<?xml version="1.0" encoding="utf-8"?>
<jocquej.PackageName.MyMapView
    ...
/>
+3

/, .

, , :

MyMapActivity.java

public class MyMapActivity extends MapActivity implements OnGestureListener,
OnDoubleTapListener{

private MapView mapView;

@Override
public void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mapView = (MapView)findViewById(R.id.mapView);

}
@Override
public boolean onDoubleTap(MotionEvent e) {
     int x = (int)e.getX(), y = (int)e.getY();;  
     Projection p = mapView.getProjection();  
     mapView.getController().animateTo(p.fromPixels(x, y));
     mapView.getController().zoomIn();  
  return true; 
}
//Here will be some autogenerated methods too

OnDoubleTap.java

public class OnDoubleTap extends MapView {

  private long lastTouchTime = -1;

  public OnDoubleTap(Context context, AttributeSet attrs) {

    super(context, attrs);
  }

  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN) {

      long thisTime = System.currentTimeMillis();
      if (thisTime - lastTouchTime < 250) {

        // Double tap
        this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
        lastTouchTime = -1;

      } else {

        // Too slow 
        lastTouchTime = thisTime;
      }
    }

    return super.onInterceptTouchEvent(ev);
  }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <azizbekyan.andranik.map.OnDoubleTap
            android:id="@+id/mapView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:enabled="true"
            android:clickable="true"
            android:apiKey="YOUR_API_KEY" />        
</LinearLayout>

android:apiKey apiKey.

+2

I was not able to get http://nocivus.posterous.com/double-clicktap-detection-on-a to work the same way as many others, since this did not allow me to use mapView = (MyMapView) findViewById(R.id.mapview);what I said was the best solution that I received, was based on a response to Double Tap Zoom in GoogleMaps Activity :

myLocationOverlay = new MyLocationOverlay(this, mapView);

MyItemizedOverlay itemizedOverlay = new MyItemizedOverlay() {
    private long systemTime = System.currentTimeMillis();

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if ((System.currentTimeMillis() - systemTime) < ViewConfiguration.getDoubleTapTimeout()) {
                mapController.zoomInFixing((int) event.getX(), (int) event.getY());
            }
            break;
        case MotionEvent.ACTION_UP:
            systemTime = System.currentTimeMillis();
            break;
        }

        return false;
    }
};
0
source

All Articles