How to find coordinates in mobile

Hi all,

        I want to find the X and Y coordinates in mobile. I am using the javascript given below it displays the coordinates in browser while running but  it is not working in mobile.

var curx = event.clientX;

You will need to use a component to get the GPS data from the mobile device.
Before trying to fetch the data you will need to check if the GPS is actually turned on on the device, if it's not you will have to prompt the user a request to enable it.

Check this out: https://www.outsystems.com/forge/component-overview/1395/location-plugin


If you aren't talking about GPS locations (silly me).
You will have to check motionevents on mobile devices, here's a snippet of code that might work in your case.

public boolean onTouchEvent(MotionEvent event) {
    int x = (int)event.getX();
    int y = (int)event.getY();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
    }
return false;
}

Joey Moree wrote:

You will need to use a component to get the GPS data from the mobile device.
Before trying to fetch the data you will need to check if the GPS is actually turned on on the device, if it's not you will have to prompt the user a request to enable it.

Check this out: https://www.outsystems.com/forge/component-overview/1395/location-plugin


If you aren't talking about GPS locations (silly me).
You will have to check motionevents on mobile devices, here's a snippet of code that might work in your case.

public boolean onTouchEvent(MotionEvent event) {
    int x = (int)event.getX();
    int y = (int)event.getY();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
    }
return false;
}

Thank you for ur response. How to implement this javascript in mobile application.

public boolean onTouchEvent(MotionEvent event) {
    int x = (int)event.getX();
    int y = (int)event.getY();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
    }
return false;
}


I'm sure this is about X and Y on the screen after an mouse event and not the GPS. Can you share a bit of what you attempt to do? 

You use this right? https://www.w3schools.com/jsref/event_clientx.asp

An example code i used for one of my mobile projects is:


onMouseDown : function(e){
            isDragged = true;
            // get mouse x and y coordinates
            startPoint.x = e.offsetX;
            startPoint.y = e.offsetY;
            // begin context path
            paintContext.beginPath();
            paintContext.moveTo(startPoint.x, startPoint.y);
        }

You have to create an event listener for it:

You can use touchstart, or any other mobile event which catches the touch.

window.addEventListener('touchstart', function(e){
    int x = (int)e.getX();
    int y = (int)e.getY();
});