Know if it's possible to access the iPhone compass in Safari using JavaScript? I see how the GPS can be accessed, but I can't figure out the compass.
Go to Settings > Privacy & Security > Location Services, then turn on Location Services. Tap Compass, then tap While Using the App.
Once the compass has been calibrated, the compass at 0 degrees will point to magnetic north — this differs from True North. If you want your iPhone's compass to always point to True North, you can change it by going to Settings > Compass > "Use True North."
With all location services enabled, the "compass" app only shows location (latitude, longitude) to the nearest arcsecond, which is about 100 feet.
On iOS, you can retrieve the compass value like this.
window.addEventListener('deviceorientation', function(e) {
console.log( e.webkitCompassHeading );
}, false);
For more informations, read the Apple DeviceOrientationEvent documentation.
Hope this helps.
You cannot access that information via javascript, unless you're using something like iPhoneGap
At the time this was true, in iOS 5 you can use the compass heading in JS. https://developer.apple.com/documentation/webkitjs/deviceorientationevent/1804777-webkitcompassheading
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With