How can I get address information by touching scre

2019-08-16 19:55发布

问题:

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

}

回答1:

Well as there isnt enough information in your question on what you have already working and what you have left to do, and what languages you are exactly using i will put this up till you put this information in your question.

I recently created an android application with google maps as part of it and used this article to get the google maps working so i can tell you that this works so if you are using Javascript in your application have a look at this article, it should help you



回答2:

TO get address you must be using GeoCoder. Now there is some error in other API of android when you use GeoCoder.

Use 2.1 to test stuff with GeoCoder



回答3:

I solved the problem.

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

When I removed it I started to use touchscreen.