Search code examples
javaandroidgoogle-mapstouchscreen

How can I get address information by touching screen on android google map


I tried all answers on this web site but None of them worked. I am using android SDK r_18 and developing an application on android 2.2. I still don't know why examples do not work.

if I add mapView.setOnTouchListener(this); to onCreate() function the at below works for one time. When the function returns false, it does not work again.

public boolean onTouch(View v, MotionEvent event) {     
    if (event.getAction() == 1) {                
        GeoPoint p = mapView.getProjection().fromPixels(
            (int) event.getX(),
            (int) event.getY());
            showToast("if 11");
            mapCon = mapView.getController();
            mapCon.animateTo(p);
            //mapCon.setZoom(mapCon.zoo);
    }       
    else
    if (event.getAction() == 2)
    {
        showToast("if 22");
      GeoPoint p = mapView.getProjection().fromPixels(
      (int) event.getX(),
      (int) event.getY());
      mapCon = mapView.getController();
      mapCon.animateTo(p);
    }
    else
        if (event.getAction() == 0)
        {
            showToast("if 00");
        }

    return (super.onTouchEvent(event));

}

Solution

  • I solved the problem.

    I was using this method "mapView.setBuiltInZoomControls(true);"

    When I removed it I started to use touchscreen.