亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序入門之指南針

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

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

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

目錄結(jié)構(gòu):

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 () {
 
 },
 
 /**
 * 頁面相關(guān)事件處理函數(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({
 
 /**
 * 當(dāng)小程序初始化完成時,會觸發(fā) onLaunch(全局只觸發(fā)一次)
 */
 onLaunch: function () {
 
 },
 
 /**
 * 當(dāng)小程序啟動,或從后臺進(jìn)入前臺顯示,會觸發(fā) onShow
 */
 onShow: function (options) {
 
 },
 
 /**
 * 當(dāng)小程序從前臺進(jìn)入后臺,會觸發(fā) onHide
 */
 onHide: function () {
 
 },
 
 /**
 * 當(dāng)小程序發(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"
}

運(yùn)行截圖:

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

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

相關(guān)文章

  • JS模塊與命名空間的介紹

    JS模塊與命名空間的介紹

    JS模塊與命名空間的介紹,需要的朋友可以參考一下
    2013-03-03
  • javascript對select標(biāo)簽的控制(option選項/select)

    javascript對select標(biāo)簽的控制(option選項/select)

    html中的select標(biāo)簽,也是asp.net中的asp:DropDownList控件,接下來介紹javascript對select標(biāo)簽的控制,感興趣的朋友可以了解下,或許本文對你有所幫助
    2013-01-01
  • 最新評論