【问题标题】:How to get device orientation correctly after main plugin deprecation主插件弃用后如何正确获取设备方向
【发布时间】:2020-03-31 19:16:56
【问题描述】:

我需要获取设备方向才能制作某种指南针。我看到old plugin |用于此的[2] 现在已弃用,建议现在使用W3C Device Orientation API

我试过这样用:

this.window.addEventListener("deviceorientation", function(event) {
    console.log(event);
}, true);

但主要方向值(alpha、beta 和 gamma)始终为空。我也尝试打开 GPS 看看是否有任何变化,但没有。

我尝试了与方向变化相关的other events,但这些都没有触发,我相信这是因为方向值始终为空。

this.window.addEventListener("orientationchange", (event) => {
    console.log(event, screen.orientation.angle);                       
}, true);

this.window.onorientationchange = (event) => { 
    console.log(event, screen.orientation.angle);
};

我做错了吗?还有其他更简单或更正确的方法来获取这些信息吗?

【问题讨论】:

  • 好吧,我还是尝试使用已弃用的插件,但当我尝试使用时它给了我错误代码 3。 Checking the docs我可以看到是因为插件找不到我设备的磁传感器。因此,如here 所述,要么我的设备没有磁传感器,要么供应商没有在操作系统中实现对它的支持。

标签: ionic-framework device-orientation


【解决方案1】:

在我的情况下,出现问题是因为我的设备不支持磁传感器(三星 Galaxy E5)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多