使用Javascript从Webb应用程序访问设备指南针 [英] Access device compass from webb app with Javascript

查看:120
本文介绍了使用Javascript从Webb应用程序访问设备指南针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Web应用程序在iPhone/Android设备上使用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 =函数(事件)

window.ondevicemotion = function(event)

有人知道您是否可以从指南针访问信息吗?

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

推荐答案

在iPhone上,您可以像这样获得指南针值.

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

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

希望获得帮助.

这篇关于使用Javascript从Webb应用程序访问设备指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆