AnsweredAssumed Answered

Using onTouchListener not returning desired values

Question asked by alejandroIngeolan on Mar 28, 2017
Latest reply on Mar 30, 2017 by ANohe-esristaff

The company now wants me to add a function to allow users to create a mark on a pressed location in the MapView. I've been trying using all the X,Y functions from the both parameters View and MotionEvent but none returns the latitude and longitude i require.

 

This function is located inside the onCreate function of the Activity

mMapView.setOnTouchListener(new MapView.OnTouchListener() {
    @Override
    public boolean onMultiPointerTap(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onDoubleTouchDrag(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onUp(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onRotate(MotionEvent motionEvent, double v) {
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {

    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return false;
    }

    @Override
    public boolean onScale(ScaleGestureDetector detector) {
        return false;
    }

    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector) {
        return false;
    }

    @Override
    public void onScaleEnd(ScaleGestureDetector detector) {

    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {

         //Already tried using getRawX and getRawY, none works
        latitude = event.getX();
        longitude = event.getY();

        Log.i("Location",latitude+","+longitude); //Used to check in the logcat the returned values.

        map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC,latitude,longitude, 16);
        mMapView.setMap(map);

        if(graphTemp != null){
            mMapView.getGraphicsOverlays().remove(graphTemp);
        }

        addMarkerToMap(); //Reusing the add marker function.

        return true; //The default value was return false
    }
});

Outcomes