# How to get reliable x and y coordinates in Android?

**URL:** <https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365>\
**Category:** Web\
**Created:** [October 31, 2021, 2:31pm UTC](https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365 "2021-10-31T14:31:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [October 31, 2021, 2:31pm UTC](https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365/1 "2021-10-31T14:31:05Z")

</div>

A simple test project demonstrates an issue (tested from Mac OS 12):  
• Put a WebCanvas and a WebLabel to the default page.  
• In the WebCanvas’ Pressed event, put: Label1.Text=x.ToString+", "+y.ToString  
• Run the project. With an Android phone (and Firefox, in my test), connect to the web app ([http://ipofcomputer:8080](http://ipofcomputer:8080)).  
• Click where the (transparent) canvas is, several times, and at several places. Notice the label shows odd values (“0, 0”, “7, 0”, etc.).  
• This works fine on Mac, but not on Android (and not Windows, too, I believe).

I need to get the correct x and y values in a project; that’s an important part of it. Can this be done otherwise, like with Javascript?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 31, 2021, 3:12pm UTC](https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365/2 "2021-10-31T15:12:42Z")

</div>

> [@Arnaud\_N](#):
>
> • Click where the (transparent) canvas is, several times, and at several places. Notice the label shows odd values (“0, 0”, “7, 0”, etc.).  
> • This works fine on Mac, but not on Android (and not Windows, too, I believe).

On Windows, Firefox or Chrome, works fine using mouse. Shows the x,y point pressed.

On Android, using Chrome, shows 0,0, just denoting “touched”, but no coordinate.

Bug in Xojo, report.

// This seems to work everywhere:

[https://jsfiddle.net/qbh941az/](https://jsfiddle.net/qbh941az/)

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [October 31, 2021, 4:05pm UTC](https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365/3 "2021-10-31T16:05:23Z")

</div>

> [@Rick\_Araujo](#):
>
> On Windows, Firefox or Chrome, works fine using mouse. Shows the x,y point pressed.

Thank you.

Good to know. I’ll check various combinations to tell my users what currently works.

> [@Rick\_Araujo](#):
>
> On Android, using Chrome, shows 0,0, just denoting “touched”, but no coordinate.

Like Firefox. I’m wondering whether clicking works on Android at all, for Xojo apps.

> [@Rick\_Araujo](#):
>
> Bug in Xojo, report.

Already done 😉 (still in “need review” state, though).

> [@Rick\_Araujo](#):
>
> This seems to work everywhere:

I’ll give it a try. Since my existing Xojo canvas is already almost complete, I’ll try to merge this script to the canvas. For this to work, I’ll need to pass the Javascript event back to Xojo; brand new to me.

Thank you.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 31, 2021, 4:23pm UTC](https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365/4 "2021-10-31T16:23:02Z")

</div>

> [@Arnaud\_N](#):
>
> I’ll try to merge this script to the canvas.

Not merge. Understand and adapt. It’s not usable as is. 😉

Cleaned up a bit more: [https://jsfiddle.net/1Lrusev6/](https://jsfiddle.net/1Lrusev6/)

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [November 3, 2021, 6:07am UTC](https://forum.xojo.com/t/how-to-get-reliable-x-and-y-coordinates-in-android/66365/5 "2021-11-03T06:07:33Z")

</div>

> [@Rick\_Araujo](#):
>
> Not merge. Understand and adapt. It’s not usable as is. 😉

Hmm… Perhaps I was not clear.  
I already have a Xojo WebCanvas with slightly complex drawing working. Re-doing all the drawings in Javascript would take me ages, especially as I’m not an expert in that language.  
Instead, I’m looking for adding the OnClick event to the existing Xojo WebCanvas (that’s what I called “merge”) because the existing Pressed event in Xojo is broken.  
But I need that Javascript event to come back to my Xojo’s already existing code and I can’t see how to receive a JS event in Xojo…  
I can’t convert the Pressed event’s code to JS either (all is already done in Xojo).

Am I missing something?
