关键代码
.wxml布局文件代码
1 |
<view>手机网络状态:{{netWorkType}}</view>
|
来自CODE的代码片
snippet_file_0.txt
.js逻辑文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Page({
data: {
netWorkType:''
},
onLoad: function () {
var that=this
wx.getNetworkType({
success: function(res) {
that.setData({
netWorkType:res.networkType
})
}
})
}
})
|
来自CODE的代码片
二:获取手机系统信息
关键代码
.wxml布局文件代码
1 2 3 4 5 6 |
<view>手机型号:{{mobileModel}}</view>
<view>手机像素比:{{mobileePixelRatio}}</view>
<view>窗口宽度:{{windowWidth}}</view>
<view>窗口高度:{{windowHeight}}</view>
<view>微信设置的语言:{{language}}</view>
<view>微信版本号:{{version}}</view>
|
来自CODE的代码片
snippet_file_0.txt
.js逻辑文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
var app = getApp()
Page({
data: {
mobileModel:'',
mobileePixelRatio:'',
windowWidth:'',
windowHeight:'',
language:'',
version:''
},
onLoad: function () {
var that=this;
wx.getSystemInfo({
success: function(res) {
that.setData({
mobileModel:res.model,
mobileePixelRatio:res.pixelRatio,
windowWidth:res.windowWidth,
windowHeight:res.windowHeight,
language:res.language,
version:res.version
})
}
})
}
})
|
来自CODE的代码片
三:用微信小程序拨打电话
关键代码
.wxml布局文件代码
1 |
<button type="default" bindtap="calling">拨打电话</button>
|
来自CODE的代码片
snippet_file_0.txt
.js逻辑文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Page({
calling:function(){
wx.makePhoneCall({
phoneNumber: '12345678900', //此号码并非真实电话号码,仅用于测试
success:function(){
console.log("拨打电话成功!")
},
fail:function(){
console.log("拨打电话失败!")
}
})
}
})
|
来自CODE的代码片
四:打开微信小程序内置地图
关键代码
.wxml布局文件代码
1 |
<button type="default" bindtap="openMap">打开地图</button>
|
来自CODE的代码片
snippet_file_0.txt
.js逻辑文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Page({
openMap:function(){
wx.getLocation({
type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function(res){
// success
wx.openLocation({
latitude: res.latitude, // 纬度,范围为-90~90,负数表示南纬
longitude: res.longitude, // 经度,范围为-180~180,负数表示西经
scale: 28, // 缩放比例
})
}
})
}
})
|
来自CODE的代码片
五:获取用户登录信息
关键代码
.wxml布局文件代码
1 2 3 4 5 6 7 8 |
<view>用户昵称:{{nickName}}</view>
<view style="display:flex">
<view style="width:100px;line-height:100px;">用户头像:</view>
<image style="width:100px;height:100px;" src="{{userInfoAvatar}}"/>
</view>
<view>性别:{{sex}}</view>
<view>所在地址(省):{{province}}</view>
<view>所在地址(市):{{city}}</view>
|
来自CODE的代码片
snippet_file_0.txt
.js逻辑文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
Page({
data: {
nickName:'',
userInfoAvatar:'',
sex:'',
province:'',
city:''
},
onLoad: function () {
var that=this;
wx.getUserInfo({
success: function(res){
// success
that.setData({
nickName:res.userInfo.nickName,
userInfoAvatar:res.userInfo.avatarUrl,
province:res.userInfo.province,
city:res.userInfo.city
})
switch(res.userInfo.gender){
case 0:
that.setData({
sex:'未知'
})
break;
case 1:
that.setData({
sex:'男'
})
break;
case 2:
that.setData({
sex:'女'
})
break;
}
},
fail: function() {
// fail
console.log("获取失败!")
},
complete: function() {
// complete
console.log("获取用户信息完成!")
}
})
}
})
|
来自CODE的代码片
六:获取自己所处的位置坐标
关键代码
.wxml布局文件代码
1 2 |
<view>纬度:{{latitude}}</view>
<view>经度:{{longitude}}</view>
|
来自CODE的代码片
snippet_file_0.txt
.js逻辑文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Page({
data: {
latitude:'',
longitude:''
},
onLoad: function () {
var that=this;
wx.getLocation({
type: 'wgs84',
success: function(res) {
that.setData({
latitude:res.latitude,
longitude:res.longitude
})
}
})
}
}
|