compass icon indicating copy to clipboard operation
compass copied to clipboard

It's off by 90°, it claims east is north

Open hipunk opened this issue 5 years ago • 5 comments

Like described it thinks east is where north is. Tested on two devices with multiple browsers.

hipunk avatar Apr 28 '20 11:04 hipunk

I ran into—and corrected—this issue, but only for Android and only for Chrome (I have more work I'm doing on this project).

The issue is that a year after Lamplightdev wrote this code, the event handler window.ondeviceorientation changed to calculate orientation relative to your device's current position, NOT True North. So every time you refresh, it's always going to point relative to the direction you're facing when you accessed the page.

The fix I've implemented so far (and again, only confirmed to work on Android and only on Chrome) is to change the event handler to window.ondeviceorientationabsolute .

See the code here (note, this version is not designed to point to True North, but a designated location here in Vancouver, WA): https://github.com/DenJansen/CompassTest/blob/master/index.html

Edit: here's the implementation in my actual project, which uses trigonometry to turn it into a compass that points at a user-designated location rather than True North: https://github.com/DenJansen/SakanyTaurus/blob/master/sakanytaurus/sakanyapp/templates/sakanyapp/compass.html

DenJansen avatar Apr 28 '20 17:04 DenJansen

@DenJansen Was that implementation in your project the last update? Or have you made any more progress in fixing this issue for other browsers?

ArmaniXR avatar Jul 28 '20 09:07 ArmaniXR

@AC0793 I'm afraid that's the last update at the moment. I've been busy with other projects, and haven't really prioritized this one, since a pub crawl app seems a little anachronistic at this time :-/

I do plan on exploring this more in the future. It's going to involve digging through documentation on event handlers for various devices/browsers, as there doesn't seem to be a universal event handler for this information.

DenJansen avatar Jul 29 '20 20:07 DenJansen

hi there thanks for modifications but, it doesn't work on chrome (iphone / android) and ios 13.5 too ! just worked on ios 9 , 10 can anybody help on this?

alitaba1349 avatar Nov 22 '20 10:11 alitaba1349

Hi, just as an FYI to everyone, I did play around with the compass a little more about a month ago. If you're interested in capturing device orientation events, I recommend checking out the Generic Sensor API. It's the best effort so far to create a universal event for capturing info from device sensors. Still nowhere near 100%, but definitely better than the ondeviceorientation events for universality: https://mobiforge.com/design-development/the-generic-sensor-api

DenJansen avatar Nov 22 '20 20:11 DenJansen