How to position sprites the same on two different phones


I am creating an app where one user moves a ball sprite and another user can see the ball on their own phone canvas. So you see the position on your canvas that is the exact same position as your friend’s ball.

Now to get the same position I am using this formula for x: (friends x position) * (screen width / (friends screen width) and for the y: (friends y position) * (screen height/ (friends screen height).

This worked perfectly and was accurate on my two test phones (oneplus x and samsung s9) but has not been 100% accurate on 3 other phones i have tested with (oneplus 7, moto g plus, and xiaomi).

The issue is always with the y position, it is slightly off, maybe by 3-5px. Could this be due to a camera notch? all three phones that do not work have a notch camera.

I am using firebase realtime database to get friend x and y coordinates and screen sizes.

Appreciate any help.