Know the direction (S, N, E, OE) with the acceleration sensor

Hello, good morning, I’m making an application which has a market that if you look north, my image looks to the north and so to the south, east or west, but only this works with cell phones that have GIROSCOPE, my ask how can I use the axes, X, Y, Z of the accelerometer to solve my problem.

Thank you

Start here: https://ionicframework.com/docs/native/device-orientation/
Then you might land here: https://github.com/apache/cordova-plugin-device-orientation
Which leads you here: https://blog.phonegap.com/migrating-from-the-cordova-device-orientation-plugin-8442b869e6cc

All 3 options should work.