标签: devicemotion

devicemotion不再工作了

我不确定这是否是正确的问题,但我的devicemotion脚本有问题.

我有一些代码在加载页面时运行,以检查是否有陀螺仪可用.我通过以下方式执行此操作:

function check_user_hardware(){

    if (mobile_size <= 600) {
        hidden = true;
    }
    console.log("checking hardware");
    giro_timer = setTimeout(update_gyro_value, 30);
    window.addEventListener("devicemotion", function(event){
        console.log("device motion?");
        if(event.rotationRate.alpha || event.rotationRate.beta || event.rotationRate.gamma){
            calculate_rotation_mesh_pos(event.rotationRate.beta, event.rotationRate.gamma);
            if (!gyroscope) {
                gyroscope = true;
                console.log("gyroscope here");
                current_interaction_mode = 'gyroscope_option';
                set_user_ui_elements();
            }
        }else{
            followMouse = true;
            console.log("no gyroscope here");
            current_interaction_mode = 'followMouse_option';
            set_user_ui_elements();
            window.addEventListener('mousemove', get_user_mouse_pos);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

这几周前工作得很好......但现在它不再工作了......当我检查控制台时,我看到以下打印件:

checking hardware
Run Code Online (Sandbox Code Playgroud)

那就是..为什么我的devicemotion事件没有被解雇?即使在我的网站上使用基本的SSL加密,它也无法正常工作?我需要某种特殊的SSL加密吗?
怎么了??
欢迎所有建议!
如果需要更多信息,我很乐意提供.
你可以在这里看到有问题的网站:gravient.thomashoek.com

javascript browser ssl devicemotion

11
推荐指数
1
解决办法
874
查看次数

在IOS 11中,后台的DeviceMotion停止工作

我的应用程序在后台报告并记录位置,高度,旋转和加速度计数据(DeviceMotion).这适用于ios 10.3.3.在IOS 11上,当设备被锁定时,我不再拥有访问运动数据.不过,高度数据和位置数据仍然会流式传输到控制台.

IOS 11中的某些内容发生了变化,导致我无法访问动态数据,或者我正在尝试以Apple现在阻止的方式访问它,例如OperationQueue.main

这是我如何开始动态更新.如果手机解锁,一切正常.如果我锁定手机,没有更新更新:

let motionManager = self.motionManager

    if motionManager.isDeviceMotionAvailable {
        motionUpdateInterval = 0.15
        motionManager.deviceMotionUpdateInterval = motionUpdateInterval

        motionManager.startDeviceMotionUpdates(using: .xArbitraryZVertical, to: OperationQueue.main) {deviceMotion, error in
            guard let deviceMotion = deviceMotion else { return }
Run Code Online (Sandbox Code Playgroud)

我找不到关于运动背景模式改变的任何信息,但似乎必须有一种方法,否则RunKeeper,Strava将会破坏.在IOS11发布之前,有人可以帮助我重新开始工作吗?

谢谢!

core-motion devicemotion ios11

9
推荐指数
1
解决办法
2732
查看次数

运行ARKit应用程序时出错"[DeviceMotion]事件引用无效"

我正在尝试使用ARKit运行一个简单的应用程序,每当我运行应用程序时,我都会收到以下错误.

2017-10-02 15:16:17.717533-0700 MyARKitProject [3702:2654241] [DeviceMotion]事件引用无效

ios devicemotion arkit

8
推荐指数
1
解决办法
427
查看次数

检测设备运动/方向支持?

我正在寻找一种方法来检查设备是否支持DeviceOrientationEvent或DeviceMotionEvent.更确切地说,我不知道该设备是否真的有加速度计.

遗憾的是window.DeviceMotionEvent,并window.ondevicemotion分别window.DeviceOrientationEventwindow.ondeviceorientation存在,虽然设备-的MacBook视网膜-没有加速度计.

我很清楚,如果事件永远不会被触发,事件监视器的回调函数也将永远不会运行.但在我的情况下,我的程序需要知道设备是否有加速度计,因为如果没有加速度计,用户应该收到通知.

不幸的是,这篇文章的答案对我的问题不起作用.

javascript accelerometer event-listener device-orientation devicemotion

7
推荐指数
1
解决办法
1955
查看次数

如何让DeviceOrientationEvent和DeviceMotionEvent在Safari上运行?

我正在尝试在我的网站上实现DeviceOrientationEvent和DeviceMotionEvent以获得3D效果。但是,该控制台不会记录任何信息,并且显然iOS 13需要用户设置权限才能开始执行此操作。我似乎无法弄清楚如何正确设置它。

我已经做了一些研究,这就是我发现的东西:https : //github.com/w3c/deviceorientation/issues/57#issuecomment-498417027

可悲的是,在线提供的所有其他方法不再可用。

window.addEventListener('deviceorientation', function(event) {
    console.log(event.alpha + ' : ' + event.beta + ' : ' + event.gamma);
});
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

[警告]在请求并授予许可之前,不会触发任何设备运动或定向事件。

javascript safari mobile-safari device-orientation devicemotion

7
推荐指数
3
解决办法
1952
查看次数

获取HTML5 deviceMotion事件以更高的速率触发

我目前正在开发广泛使用deviceOrientation和deviceMotion HTML5 API的移动Web应用程序.在大多数移动浏览器中,事件每50毫秒触发一次,这对我所需的精度来说太慢了:有没有办法以更高的速率获取运动数据?

我查看了W3C DeviceOrientation事件规范,我发现事件的interval属性给出了触发率devicemotion,不幸的是readonly(另外,我不确定这是否只是浏览器实现的刷新率的指标,或者如果这实际上设置了浏览器的刷新率).我看到该initAccelerometerEvent方法可能允许更改此值,但我无法在我的Javascript代码中找到如何直接使用它.

或者,我认为我们可以获得加速度计/陀螺仪的当前值:如果存在这样的方法,我们可以在setInterval方法中使用它,以便我们设置我们想要的刷新率.不幸的是,我找不到这样的方法.

因此,任何以更高的速率获得运动值的建议都是最受欢迎的.非常感谢您的帮助!

javascript html5 device-orientation devicemotion

6
推荐指数
0
解决办法
1064
查看次数

如何使用加速度计和Swift快速检测苹果手表的位置?

我已经为Apple Watch创建了一个应用程序.逻辑是,当用户举手并点击应用程序中的按钮时.那时我将获取加速度计值.每当用户举手并达到捕获位置时,我都必须向iPhone发送消息.

对我来说正确地得到了值但是,它总是会根据加速度计给出值.这意味着用户不会抬起手但加速度计值匹配.因此值将发送到移动设备.

func startUpadateAccelerometer() {
        self.motionManager.accelerometerUpdateInterval = 1.0 / 10.0
        self.motionManager.startAccelerometerUpdates(to: OperationQueue()) { (accelerometerData, error) -> Void in
            guard accelerometerData != nil else
            {
                print("There was an error: \(String(describing: error))")
                return
            }

            DispatchQueue.main.async {
                if(self.can_reset){
                    let differenceX : Bool = self.validateButtom(currentValue: accelerometerData!.acceleration.x, inititalValue: self.gravityReference.x)
                    let differenceY : Bool = self.validateButtom(currentValue: accelerometerData!.acceleration.y, inititalValue: self.gravityReference.y)

                    if(differenceX && differenceY && self.gravityOffsetDifference(currentValue: accelerometerData!.acceleration.x, referenceValue: self.gravityReference.x ) && self.gravityOffsetDifference(currentValue: accelerometerData!.acceleration.y, referenceValue: self.gravityReference.y)){
                        WKInterfaceDevice().play(.success)
//                        self.addLog(_logStr: EventsTypes.Achievements1.rawValue)

                        self.logString += String(format: "X: %0.3f Y: %0.3f Z: …
Run Code Online (Sandbox Code Playgroud)

accelerometer ios devicemotion apple-watch swift3

6
推荐指数
1
解决办法
479
查看次数

在 Android 设备上使用 Angular Ionic 加速计事件频率在前 5 分钟减慢

我在用

window.addEventListener('devicemotion', event => this.watchDeviceMotion(event))

watchDeviceMotion(event: any) {

  let motionData = {
    x: event.acceleration.x,
    y: event.acceleration.y,
    z: event.acceleration.z,
  }
  let rotationData = {
    alpha: event.rotationRate.alpha,
    beta: event.rotationRate.beta,
    gamma: event.rotationRate.gamma
  }

  if (this.getSensorData) {
    // console.log(JSON.stringify(motionData))
    // console.log(JSON.stringify(rotationData))
    this.userData.motionData.push(motionData)
    this.userData.rotationData.push(rotationData)
  }
}
Run Code Online (Sandbox Code Playgroud)

使用带有 Angular 的 Ionic 访问 Android 设备上的加速度计数据。在应用程序内部时,事件以 60 Hz 的频率运行,但当应用程序切换到后台时,频率在前 5 分钟内下降约 9-10 Hz,并且在某个时刻仍处于后台时,它会以 60 Hz 的频率返回并且无限期地保持这样。

我也在使用后台插件

this.backgroundMode.enable();
this.backgroundMode.on('activate').subscribe(() => {
  this.backgroundMode.disableWebViewOptimizations();
});
Run Code Online (Sandbox Code Playgroud)

我尝试将 disableBatteryOptimizations() 添加到具有 config.xml 中相应条件的后台插件,但仍然没有运气。

我还尝试了 Device Motion 和 Gyroscope 的插件,但它们的行为相同。

我应该如何防止频率变慢?有没有其他人遇到过这个问题?

android ionic-framework devicemotion angular ionic4

6
推荐指数
1
解决办法
277
查看次数

HTML5/Javascript 使用 devicemotion/deviceorientation 计算设备速度

是否可以使用 devicemotion/deviceorientation HTML5 API 以公里/小时为单位计算设备速度?

我想知道用户是否在走路/跑步/不动,我不能使用地理定位 API,因为它也必须在建筑物内工作。

html javascript devicemotion

5
推荐指数
1
解决办法
1934
查看次数

iOS DeviceMotion 横向与纵向上的偏航和滚动

我正在使用陀螺仪在 iOS 上实现 360 度视频查看器,我需要为视频进行两次旋转,我使用了这个;

self.motionManager.deviceMotionUpdateInterval = 1.0/60.0;
    if (self.motionManager.isDeviceMotionAvailable) {
        CMDeviceMotion *deviceMotion = self.motionManager.deviceMotion;
        CMAttitude *currentAttitude = deviceMotion.attitude;
        //[self.motionManager startDeviceMotionUpdates];
        [self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical];
    }
Run Code Online (Sandbox Code Playgroud)

然后我这样做:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CMDeviceMotion *currentDeviceMotion = self.motionManager.deviceMotion;
CMAttitude *currentAttitude = currentDeviceMotion.attitude;     
float roll  = currentAttitude.roll;
float pitch = currentAttitude.pitch;
float yaw = currentAttitude.yaw;

if (isLandscape)
{
    _player.rotation = -yaw + currentLocation.x;

    // 0 roll is phone flat, so we need to rotate -90 degrees to adjust vertical phone
    if (orientation == UIDeviceOrientationLandscapeLeft) …
Run Code Online (Sandbox Code Playgroud)

portrait objective-c ios devicemotion 360-virtual-reality

5
推荐指数
0
解决办法
857
查看次数

应用程序在后台运行时读取加速度计数据

我想构建一个 Ionic 应用程序,当应用程序最小化(在后台运行)时,该应用程序仍然可以使用加速度计数据。

我尝试过使用:

前两个在前台工作,但当应用程序在后台时不起作用(加速度计读数暂停并在前台再次恢复)。即使我使用这个 polyfill,通用传感器 API 也根本无法工作: https: //github.com/kenchris/sensor-polyfills

我还尝试了离子背景模式插件,但是,加速度计读数仍然在后台暂停。 https://ionicframework.com/docs/native/background-mode

Ionic 应用程序如何在后台使用加速计?有没有我不知道其存在的插件(例如,Ionic 背景地理定位允许应用程序在后台接收位置)?还有其他办法吗?

background accelerometer ionic-framework devicemotion sensors

5
推荐指数
0
解决办法
285
查看次数

WKWebView iOS 13 中的 DeviceMotion 和 DeviceOrientation

我想在 iOS 13+ 中使用DeviceMotionDeviceOrientation事件WKWebView。我正在使用下面的代码

<html>
    <style>
        #container{
            margin: 20px; 
            padding: 20px
        }
        #deviceType{
            text-align: center; 
            font-family: Arial, Helvetica, sans-serif; 
            font-size: 3rem;
            font-weight: bold; 
            color: #08f
        }
        #permission{
            padding: 2rem 5rem;
            background: #08f;
            color: white; 
            margin-top: 30;
            font-family: Arial, Helvetica, sans-serif; 
            font-size: 3rem;
            border: none; 
            border-radius: 1rem
        }
        #permissionStatus{
            text-align: center; 
            font-family: Arial, Helvetica, sans-serif; 
            font-size: 2.5rem;
            font-weight: 600; 
            color: red;
            margin-top: 30px
        }
    </style>
    <body>
        <div id="container">
                <div id="deviceType"></div>
                <div style="text-align: center">
                    <button id="permission">Ask …
Run Code Online (Sandbox Code Playgroud)

ios devicemotion wkwebview ios-permissions

1
推荐指数
1
解决办法
2759
查看次数