本文編輯: Flyinthesky瀏覽 4995
版權所有,嚴禁轉載
一個類似于指南針的接口,導航類APP應用接口。
接口 | 說明 |
---|---|
wx.onCompassChange(CALLBACK) | 監聽羅盤數據,頻率:5次/秒 |
【圖片】
【代碼】
wxml
<view class="container">
<template is="header" data="{{title: 'onCompassChange'}}"/>
<view class="page-body">
<view class="page-body-wrapper">
<text class="page-body-text">旋轉手機即可獲取方位信息</text>
<view class="direction">
<text class="direction-value">{{direction}}</text>
<text class="direction-degree">o</text>
</view>
</view>
</view>
<template is="footer" />
</view>
js
Page({
data: {
direction: 0
},
onReady: function () {
var that = this
wx.onCompassChange(function (res) {
that.setData({
direction: parseInt(res.direction)
})
})
}
})
wxss
.direction {
margin-top: 100rpx;
display: flex;
}
.direction-value {
font-size: 200rpx;
}
.direction-degree {
font-size: 40rpx;
}
wx.onCompassChange(CALLBACK)
【方法內容描述】
參數 | 類型 | 描述 |
---|---|---|
direction | Number | 面對的方向度數 |
wx.onCompassChange(function (res) {
console.log(res.direction)
})