compass.md 1.9 KB
Newer Older
M
mehaotian 已提交
1
### uni.onCompassChange(CALLBACK)
2
监听罗盘数据,频率:5次/秒,接口调用后会自动开始监听,可使用 ``uni.offCompassChange`` 取消监听。
M
mehaotian 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

**CALLBACK 返回参数**

|参数|类型|说明|
|:-|:-|:-|
|direction|Number|面对的方向度数|

**Tips**
- H5端获取罗盘信息,需要部署在 **https** 服务上,本地预览(localhost)仍然可以使用 http 协议。

**示例**

```javascript
uni.onCompassChange(function (res) {
	console.log(res.direction);
});
```

21 22 23 24 25
### uni.offCompassChange(CALLBACK)
取消监听罗盘数据。

**平台差异说明**

DCloud_JSON's avatar
DCloud_JSON 已提交
26 27 28
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|快手小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|HBuilderX 2.9.6+|HBuilderX 2.9.6+|基础库 2.9.3+|x|x|x|x|√|
29

2
23700113@qq.com 已提交
30 31 32
**Tips**
- `CALLBACK`为调用`uni.onCompassChange`时传入的`CALLBACK`

M
mehaotian 已提交
33 34 35 36 37
### uni.startCompass(OBJECT)
开始监听罗盘数据。

**平台差异说明**

DCloud_JSON's avatar
DCloud_JSON 已提交
38 39 40
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|快手小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|√|√|√|x|√|√|√|√|
M
mehaotian 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

**OBJECT 参数说明**

|参数名|类型|必填|说明|
|:-|:-|:-|:-|
|success|Function|否|接口调用成功的回调|
|fail|Function|否|接口调用失败的回调函数|
|complete|Function|否|接口调用结束的回调函数(调用成功、失败都会执行)|

**示例**

```javascript
uni.startCompass();
```

### uni.stopCompass(OBJECT)
停止监听罗盘数据。

**OBJECT 参数说明**

|参数名|类型|必填|说明|
|:-|:-|:-|:-|
|success|Function|否|接口调用成功的回调|
|fail|Function|否|接口调用失败的回调函数|
|complete|Function|否|接口调用结束的回调函数(调用成功、失败都会执行)|

**示例**

```javascript
uni.stopCompass();
W
wanganxp 已提交
71
```