Skip to content

Guidance needed: how to acquire compass headings in a future-compatible manner? #137

@juj

Description

@juj

Today there exists an event deviceorientationabsolute that can be used to register to device orientation events that are relative to the magnetic north pole (for 1D compass heading calculations)

This event is available on other browsers except Safari.

On Safari window.addEventListener('deviceorientationabsolute', ...) does not work, but instead one must first call DeviceOrientationEvent.requestPermission() and after that Promise resolves to a success, register to the window.addEventListener('deviceorientation', ...) event, and use DeviceOrientationEvent.webkitCompassHeading to acquire the 1D compass heading direction.

In other browsers today, I understand that one does not need to call DeviceOrientationEvent.requestPermission() before registering a deviceorientationabsolute event handler, though I presume that since the function is in the spec, that in the future this may also be required.

But this gives a problem: what kind of code should one write in order to precisely register to get 1D compass heading directions in a manner that will be forward-compatible to future Firefox, Chrome and Safari browsers?

We can feature test whether DeviceOrientationEvent.requestPermission() exists and call it before registering a handler, but how does one know precisely whether to register 'deviceorientation' or 'deviceorientationabsolute' events?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions