Android itemizedOverlay's onTap action overrided

烈酒焚心 提交于 2019-12-03 09:48:50

Found the answer - had to include the:

if(super.onTap(p, mapView)) {
                return true;
            }

in the beginning of the public boolean onTap (final GeoPoint p, final MapView mapView) function.

you can use onTouch method

@Override
        public boolean onTouchEvent(MotionEvent event, final MapView mapView) {
            final int action=event.getAction();
            final int x=(int)event.getX();
            final int y=(int)event.getY();
            result = false;
            if (action==MotionEvent.ACTION_DOWN) {
                downPressed = true;
                drag = false;
/* here check for the items is null or not and then after get all the items 
   so if you click on map and on that place if the item on placed then it will
   check for the item hit other it refer the user click on map not on marker 

*/
                if(items!=null){
                    for(int i=0;i<items.size();i++){
                        OverlayItem item = items.get(i);
                        Point mp=new Point(0,0);
                        mapView.getProjection().toPixels(item.getPoint(), mp);
                        xDragTouchOffset=x-mp.x;
                        yDragTouchOffset=y-mp.y;
                        if (hitTest(item, marker, x-(mp.x-(xDragImageOffset+xDragTouchOffset*2)), y-(mp.y-((yDragImageOffset/2)+yDragTouchOffset)))) {
                            result = true;
                            markerIndex = i;
                            task_id = Long.parseLong(item.getTitle());
                            downPressed = false;
                            markerPressed = true;
                            break;
                        }
                    }
                }
        }
        else if (action==MotionEvent.ACTION_MOVE) {
     // here user pressed and drag the downPressed set to false so it will indicate that user want to move the map and drag set to true;
            downPressed = false;
            drag=true;
        }
        else if (action==MotionEvent.ACTION_UP) {
    // if user not drag then this downPressed is true and it will return the screen and map coordinate
            if(downPressed){

                    tempPoint = mapView.getProjection().fromPixels(x, y);
                    markerLat = tempPoint.getLatitudeE6()/1e6;
                    markerLng = tempPoint.getLongitudeE6()/1e6;
                    mapView.invalidate();
            }

            drag = false;
            downPressed = false;
        }
        return(result | super.onTouchEvent(event, mapView));
    }

here i can do this way hope you get some idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!