accessing iPhone compass with JavaScript

别说谁变了你拦得住时间么 提交于 2019-12-01 04:05:56
christo16

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

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.

I advise you to use LeafletJS with this plugin
https://github.com/stefanocudini/leaflet-compass

very simple to use with events and methods.

You can try a demo here:
http://labs.easyblog.it/maps/leaflet-compass/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!