谷歌地图上的OnTouch删除了mapview中的拖动和滚动以及缩放控件不会出现在触控上

时间:2013-02-21 05:05:42

标签: android google-maps android-mapview

好的,因为问题说我有一个mapview和一个OnTouchListener设置它,在Ontouch函数中我在地图上设置了一个叠加图像。但是在这个过程中,现在以某种方式删除了mapview中的缩放控件和拖动功能。请帮帮我。 我已经将setzoomcontrolson设置为true(无效)。请帮助。

public class marker extends ItemizedOverlay {

    Context mContext;

    OverlayItem overlayitem;

    Drawable marker;

    private int xDragImageOffset=0;

    private int yDragImageOffset=0;

    private int xDragTouchOffset=0;

    private int yDragTouchOffset=0;

    OverlayItem inDrag;

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

    public marker(Drawable defaultMarker, Context context) {

          super(boundCenterBottom(defaultMarker));

          mContext = context;

          marker=defaultMarker;
        } 

    public void addOverlay(OverlayItem overlay) {

        mOverlays.clear();

        mOverlays.add(overlay);

        populate();
    }

    @Override

    protected OverlayItem createItem(int i) {

       return mOverlays.get(i);
    }



        @Override

    public int size() {

    return mOverlays.size();
    }

        @Override

    public boolean onTap(GeoPoint geoPoint, MapView mapView){

    boolean tappedAnOverlay = super.onTap(geoPoint, mapView);

        if (tappedAnOverlay) {

            places.gp=geoPoint;  // do your thing if hit an overlay

        }

        else {
            // no overlay found in that location
        }


        MapController mc=mapView.getController();

        mc.animateTo(geoPoint);

            return true;
    }



}
this is my marker overlays file 

    public class places extends MapActivity implements android.view.View.OnClickListener/*,OnTouchListener*/  {

        MapView mapView;

        MapController mc;

        Button srchbtn;

        EditText searchstring;

        marker itemizedoverlay;

    public static List<Overlay> mapOverlays;

        OverlayItem overlayitem;

        public static GeoPoint gp;

        Button back;

        String s1;

        String s2="yourprofile";

        String s3="partnerprofile";

        public int zoom=5;

        @Override

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.place);

            mapView = (MapView) findViewById(R.id.mapview);

            mapView.setBuiltInZoomControls(true);

            srchbtn=(Button)findViewById(R.id.searchbtn);

            searchstring=(EditText)findViewById(R.id.edplnm);

            srchbtn.setOnClickListener(this);

            mapView.setClickable(true);

            mapView.setBuiltInZoomControls(true);

            mapOverlays = mapView.getOverlays();

            Drawable drawable = this.getResources().getDrawable(R.drawable.marker);

            itemizedoverlay = new marker(drawable, this);

            back=(Button)findViewById(R.id.btnbk);

            back.setOnClickListener(this);

            s1=getIntent().getStringExtra("ClassName");

            mc=mapView.getController();

            mc.setZoom(zoom);

            gp=new GeoPoint((int)(21.7679 * 1E6), (int)(78.8718 * 1E6));

            mc.animateTo(gp);

                   // mapView.setOnTouchListener(this);


        }

     @Override

        protected boolean isRouteDisplayed() {

            return false;
        }

        @Override

        public void onClick(View arg0) {

            // TODO Auto-generated method stub

            switch(arg0.getId())

            {

            case R.id.searchbtn:String s = searchstring.getText().toString();

                                String[] vals =s.split(":");

                                float lat;

                                float logi;

                                lat=Float.parseFloat(vals[0]);

                                logi=Float.parseFloat(vals[1]);

                                gp = new GeoPoint((int)(lat * 1E6), (int)(logi * 1E6));

                                MapController mc=mapView.getController();

                                mc.setZoom(80);

                                mc.animateTo(gp);

                                overlayitem = new OverlayItem(gp, "", "");

                                itemizedoverlay.addOverlay(overlayitem);

                                mapOverlays.add(itemizedoverlay);

                                break;

            case R.id.btnbk: int Lat;

                             int Logi;

                             Lat=gp.getLatitudeE6();

                             Logi=gp.getLongitudeE6();

                             boolean val=s1.equals(s2);

                             boolean val2=s1.equals(s3);

                             Intent I1=new Intent(places.this,yourprofile.class);

                             Intent I2=new Intent(places.this,partnerprofile.class);

                             if(val)

                             {

                             I1.putExtra("LAT",Lat);

                             I1.putExtra("LONG",Logi);

                             setResult(RESULT_OK,I1); 

                             finish();


                             }else

                                 if(val2)

                                 {

                                     I2.putExtra("LAT",Lat);

                                     I2.putExtra("LONG",Logi);

                                     setResult(RESULT_OK,I2); 

                                     finish();
                                 }

                             break;


            }

    }

    /*public boolean onTouch(View v, MotionEvent e) {

            if(e.getAction()==MotionEvent.ACTION_UP){

             Projection p =((MapView)v).getProjection();

             gp = p.fromPixels((int) e.getX(), (int) e.getY());

             overlayitem = new OverlayItem(gp, "", "");

             itemizedoverlay.addOverlay(overlayitem);

             mapOverlays.add(itemizedoverlay);

             mc.setZoom(zoom);

             mc.animateTo(gp);

             searchstring.setText(((float)gp.getLatitudeE6())/1000000 + ":" +

    ((float)gp.getLongitudeE6())/1000000);

            }

            return true;
        }*/



    }

这是我的地方类文件

1 个答案:

答案 0 :(得分:0)

以下是您可能想要使用的Sample Working Demo

它将帮助您使用缩放和触摸功能为Mapview拖放图像。

希望它会有所帮助。