- JS API 列表
- 基础
- 网络
- 媒体
- 地图
- 文件
- 开放接口
- 数据缓存
- 地理位置
- 设备
- 画布
- 界面
- 页面导航
- 侧边栏能力
- 行业开放
- AI/AR能力
- 第三方平台
- TTML
- 转发和挂载
- 其它
- 直播能力
tt.startGyroscope
更新时间 2024-08-16 07:59:35
收藏
我的收藏创建陀螺仪实例,准备获取陀螺仪数据。
语法
js复制tt.startGyroscope(options);
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
interval | number | 50 | 否 | 获取陀螺仪数据的间隔时间,单位为毫秒(ms),默认大小为 50,最小值为 50。 | 2.87.0 |
success | function | | 否 | 接口调用成功的回调函数 | 2.87.0 |
fail | function | | 否 | 接口调用失败的回调函数 | 2.87.0 |
complete | function | | 否 | 接口调用结束的回调函数 | 2.87.0 |
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
errMsg | string | "startGyroscope:ok" | 2.87.0 |
回调失败
属性名 | 类型 | 说明 | 最低支持版本 |
errMsg | string | "startGyroscope:fail " + 详细错误信息 | 2.87.0 |
errNo | number | 错误码 | 2.87.0 |
错误说明
errNo | errMsg | 说明 | 最低支持版本 |
10201 | startGyroscope:fail privacy permission is not authorized | 3.19.0 | |
10202 | startGyroscope:fail api scope is not declared in the privacy agreement | 3.19.0 | |
20000 | startGyroscope:fail invalid param | 参数错误 | 2.87.0 |
21401 | startGyroscope:fail the value of 'interval' is too small. It must be >= 50. | 时间间隔必须大于50 | 2.87.0 |
21402 | startGyroscope:fail sensor disable | 传感器不可用 | 2.87.0 |
扫码体验
代码示例
js复制//设置每隔100ms刷新一次陀螺仪数据
tt.startGyroscope({
interval: 100,
success() {
tt.onGyroscopeChange(function (params) {
console.log("陀螺仪数据:x ", params.x);
console.log("陀螺仪数据:y ", params.y);
console.log("陀螺仪数据:z ", params.z);
console.log("陀螺仪数据:t ", params.t);
});
},
fail(res) {
console.warn(res); //失败时候进入这里
},
});
Bug & Tip
无
点击纠错