I use the Cordova plugin for the moment. It works fine with IOS devices and more or lass with some Android devices but it doesn’t work with some other Android devices such as Xiaomi.
It could be very nice to have a good native working tool (that does not need to ask the permissions to work if it is possible).
With the plugin @awesome-cordova-plugins/device-orientation, you can get the key trueHeading which is relative to the geographic North Pole in degrees.
It works fine but seems to be not up to date and so, it is not supported on the newest devices.