最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序入門之指南針

 更新時間:2020年10月22日 15:30:13   作者:yunfeather  
這篇文章主要為大家詳細介紹了微信小程序入門之指南針,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

微信小程序入門案例——指南針,供大家參考,具體內(nèi)容如下

涉及技術:獲取地理位置、監(jiān)聽指南針角度

目錄結(jié)構:

pages\index\index.js

Page({
 
 /**
 * 頁面的初始數(shù)據(jù)
 */
 data: {
 rotate:0,
 degree:'未知',
 direction:'',
 lat:0,
 lon:0,
 alt:0
 },
 
 /**
 * 生命周期函數(shù)--監(jiān)聽頁面加載
 */
 onLoad: function (options) {
 var that = this;
 wx.getLocation({
 altitude: true,
 success:function(res){
 that.setData({
  lat:res.latitude.toFixed(2),
  lon:res.longitude.toFixed(2),
  alt:res.altitude.toFixed(2)
 })
 }
 })
 wx.onCompassChange(function(res){
 let degree = res.direction.toFixed(0);
 that.getDirection(degree)
 that.setData({
 rotate:360 - degree
 })
 })
 
 },
 /**
 * 判斷方向
 */
 getDirection:function(deg){
 let dir = '未知';
 if(deg>=340||deg<=20){
 dir='北';
 }else if(deg>20&&deg<70){
 dir='東北';
 }else if(deg>=70&&deg<=110){
 dir='東';
 }else if(deg>110&&deg<160){
 dir='東南';
 }else if(deg>=160&&deg<=200){
 dir='南';
 }else if(deg>200&&deg<250){
 dir='西南';
 }else if(deg>=250&&deg<=290){
 dir='西';
 }else if(deg>290&&deg<340){
 dir='西北';
 }
 this.setData({
 degree:deg,
 direction:dir
 })
 },
 
 /**
 * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
 */
 onReady: function () {
 
 },
 
 /**
 * 生命周期函數(shù)--監(jiān)聽頁面顯示
 */
 onShow: function () {
 
 },
 
 /**
 * 生命周期函數(shù)--監(jiān)聽頁面隱藏
 */
 onHide: function () {
 
 },
 
 /**
 * 生命周期函數(shù)--監(jiān)聽頁面卸載
 */
 onUnload: function () {
 
 },
 
 /**
 * 頁面相關事件處理函數(shù)--監(jiān)聽用戶下拉動作
 */
 onPullDownRefresh: function () {
 
 },
 
 /**
 * 頁面上拉觸底事件的處理函數(shù)
 */
 onReachBottom: function () {
 
 },
 
 /**
 * 用戶點擊右上角分享
 */
 onShareAppMessage: function () {
 
 }
})

pages\index\index.wxml

<view class="container">
 <image src="/images/1.jpg" mode="widthFix" style="transform:rotate({{rotate}}deg);"></image>
 <view class="status">
 <text class="bigTxt">{{degree}}°{{direction}}</text>
 <text class="smallTxt">北緯{{lat}}東經(jīng){{lon}}</text>
 <text class="smallTxt">海拔{{alt}}米</text>
 </view>
</view> 

pages\index\index.wxss

.container{
 height: 100vh;
 display: flex;
 flex-direction: column;
 align-items: center;
 justify-content: space-around;
 color: #A46248;
}
image{
 width: 80%;
}
.status{
 display: flex;
 flex-direction: column;
 align-items: center;
}
.bigTxt{
 font-size: 30pt;
 margin: 15rpx;
}
.smallTxt{
 font-size: 20pt;
 margin: 15rpx;
} 

app.js

App({
 
 /**
 * 當小程序初始化完成時,會觸發(fā) onLaunch(全局只觸發(fā)一次)
 */
 onLaunch: function () {
 
 },
 
 /**
 * 當小程序啟動,或從后臺進入前臺顯示,會觸發(fā) onShow
 */
 onShow: function (options) {
 
 },
 
 /**
 * 當小程序從前臺進入后臺,會觸發(fā) onHide
 */
 onHide: function () {
 
 },
 
 /**
 * 當小程序發(fā)生腳本錯誤,或者 api 調(diào)用失敗時,會觸發(fā) onError 并帶上錯誤信息
 */
 onError: function (msg) {
 
 }
})

app.json

{
 "pages":[
 "pages/index/index"
 ],
 "window":{
 "backgroundTextStyle":"light",
 "navigationBarBackgroundColor": "#fff",
 "navigationBarTitleText": "指南針",
 "navigationBarTextStyle":"black"
 },
 "permission":{
 "scope.userLocation":{
 "desc":"你的位置信息將用于小程序指南針的效果展示"
 }
 },
 "style": "v2",
 "sitemapLocation": "sitemap.json"
}

運行截圖:

為大家推薦現(xiàn)在關注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

绥德县| 凤翔县| 和平县| 文安县| 诸暨市| 正镶白旗| 博罗县| 盐亭县| 珠海市| 正镶白旗| 珲春市| 专栏| 奎屯市| 永寿县| 天等县| 诸暨市| 西和县| 汉寿县| 开原市| 武宣县| 交城县| 越西县| 河间市| 灵宝市| 克拉玛依市| 南充市| 曲沃县| 开封市| 广汉市| 阿瓦提县| 罗田县| 定日县| 友谊县| 保康县| 黎平县| 锦州市| 松原市| 镇江市| 永定县| 鄱阳县| 苍梧县|