您的位置:首頁技術文章
文章詳情頁

微信小程序新手教程之怎么獲取系統信息和地理位置

瀏覽:151日期:2022-07-15 18:29:27

微信小程序新手教程之怎么獲取系統信息和地理位置,本篇默認已經成功安裝微信小程序工具,來和小編一起看看吧

三個接口都是微信提供的。

index.js

//index.js//獲取應用實例var app = getApp() Page({ data:{ userinfo : {}, systemInfo:{}, location :{} }, onShow:function(){ var that = this; // 獲取用戶資料 wx.getUserInfo({ success:function(res){ that.setData({ userinfo:res.userInfo }); } }); // 獲取系統資料 wx.getSystemInfo({ success:function(res){ that.setData({ systemInfo : res }); } }); // 獲取位置信息 wx.getLocation({ success:function(res){ that.setData({ location:res }); } }); } })

index.wxml

<view class="header"> <image class="user-header" src="{{userinfo.avatarUrl}}"></image> <text >{{userinfo.province}} {{userinfo.city}}</text> <text >{{userinfo.nickName}}</text> </view> <view class="slice-line"></view> <view class="center"> <text class="text">系統信息</text> </view> <view class="info-box"> <text class="info-text">手機型號:{{systemInfo.model}}</text> <text class="info-text">設備像素比:{{systemInfo.pixelRatio}}</text> <text class="info-text">窗口寬度:{{systemInfo.windowWidth}}</text> <text class="info-text">窗口高度:{{systemInfo.windowHeight}}</text> <text class="info-text">微信設置的語言:{{systemInfo.language}}</text> <text class="info-text">微信版本號:{{systemInfo.version}}</text> </view> <view class="center"> <text class="text">位置信息</text> </view> <view class="slice-line"></view> <view class="info-box"> <text class="info-text">緯度:{{location.latitude}}</text> <text class="info-text">經度:{{location.longitude}}</text> <text class="info-text">速度:{{location.speed}}</text> <text class="info-text">位置精確度:{{location.accuracy}}</text> </view> <view style="margin-top:100rpx;width:100%;height:2rpx;"></view>

最后效果圖

微信小程序新手教程之怎么獲取系統信息和地理位置

好了。文本介紹了三個接口的使用方式,具體怎么發揮,大家自行判斷吧。

下面小編就給大家介紹一種一個小程序吧

嗨圖功能

微信小程序新手教程之怎么獲取系統信息和地理位置

1、專題——DIY圖片的模板,點擊可以生成使用,分享到朋友圈。

2、分享墻——用戶上傳的自己DIY作品。

3、立即制作——可以用自己的圖來DIY。

4、告訴我——告訴產品的改進,內容的增加。

想要體驗怎么制作屬于自己個性朋友圈照片的用戶,掃一掃下面的二維碼就可以啦!還等什么,趕緊掃碼體驗,開啟你的嗨圖之旅吧!

微信小程序新手教程之怎么獲取系統信息和地理位置
標簽: 微信
相關文章:
国产综合久久一区二区三区