Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access device compass from web app with Javascript

Is it possible to access the compass with Javascript on an iphone/ android device from a web app? Have been looking all over the net for hours I know you can access the accelerometer with

window.ondevicemotion = function(event)

Does anyone know if you can access the information from the compass??

like image 259
Christopher Avatar asked Sep 07 '26 05:09

Christopher


1 Answers

On iPhone, you can get the compass value like this.

window.addEventListener('deviceorientation', function(e) {
    console.log(e.webkitCompassHeading);
}, false);

Hope this help.

like image 187
Simon Arnold Avatar answered Sep 11 '26 01:09

Simon Arnold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!