3

I have the following code to show my actual location on Google Maps:

public class LocationProjectActivity extends MapActivity implements OnTouchListener {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private MyOverlays itemizedoverlay;
private MyLocationOverlay myLocationOverlay;
private GeoPoint MyPoint;
public static int longitude;
public static int latitude;
private GeoPoint destinationPoint;

public void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  setContentView(R.layout.main);
  mapView = (MapView) findViewById(R.id.mapview);
  mapView.setBuiltInZoomControls(true);
  mapView.setSatellite(true);
  mapView.computeScroll();
  mapController = mapView.getController();
  mapController.setZoom(13);
  locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new GeoUpdateHandler());
  myLocationOverlay = new MyLocationOverlay(this, mapView);
  mapView.getOverlays().add(myLocationOverlay);
  myLocationOverlay.runOnFirstFix(new Runnable() {
    public void run() {
      mapView.getController().animateTo(myLocationOverlay.getMyLocation());
    }
  });
}

@Override
public boolean onTouch(View v, MotionEvent event) {
  System.out.println("SCREEN WAS CLICKED");
  return true;
}

What I want to do is catch when I touch the screen, but the method is never called. I already searched and found this: OnTouch in map

I tried everything and the only code that works was this:

mapView.setOnTouchListener(new OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
    // Your code and remember to return true!        
    return (true);
  }
});

The problem is that if I use this code, my MapView loses the natural fling and zoom that it already has, so how can I have everything in my MapView?

Thank you.

Community
  • 1
  • 1
Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75

1 Answers1

0

If you just want to see when you touch the screen, you can still return false which will allow all the other drag and zoom touch events to work.

You would only return true if you want a separate touch event to NOT continue to the others.

leenephi
  • 900
  • 5
  • 13
  • if i do this with the mapView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event)... only the first time works, but with the implements OnTouchListener method never works – Fernando Santiago Jul 21 '12 at 20:26
  • Does mapView.setClickable(true) do anything? – leenephi Jul 21 '12 at 20:33
  • Nothing This code only works the first time: `mapView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { System.out.println("SCREEN WAS TOUCHED"); return false; } });` – Fernando Santiago Jul 21 '12 at 20:37
  • But if i want to call the `@Override public boolean onTouch(View v, MotionEvent event) { System.out.println("SCREEN WAS TOUCHED"); return false; }` implementing the OnTouchListener, it does not work – Fernando Santiago Jul 21 '12 at 20:38
  • Well, either way, to use the implementation of OnTouchListener, you still need to call mapView.setOnClickListener(this); – leenephi Jul 21 '12 at 20:52
  • I know, thats the wierd think, and more wierder is that only the first time work, the next time i touch the screen nothing happens – Fernando Santiago Jul 21 '12 at 22:03