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

查看:64
本文介绍了使用 Javascript 从 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 从 Web 应用程序访问设备指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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