实训第四天 获取手机信息,地图定位

1.mine页面背景图片
在mine.wxml里面

<view class="container"> 

<view style='width:100%;height:450rpx'>   //图片大小设置

<image class='auto-img' src='../../images/bg.jpg' ></image>  //图片位置格式引用auto-img类

</view>

</view>
在mine.wxss
.container{

width: 100%;

height: 100%;

}

.auto-img{   

width: 100%;

height: 100%;

display: block;  //占一行,就不会有白边

margin-top: -188px;  //设置照片垂直位置

}

2.求适应页面的高度:图片宽度/适应的宽度*图片高度;或者直接用rpx固定它的大小
3.在页面背景中居中放一个头像和用户名
注意image标签里面不能套任何标签
先把用户头像设定好格式后放进页面中
<image class='usericon' src='../../asserts/icons/my.png'></image>
usericon类设置格式:

.usericon{

height:200rpx;

width:200rpx;

border-radius:50%;

}

再将头像弄到页面中间:用margin-top不行,所以考虑定位,将背景图片去掉,再给头像标签加个背景图片,但背景图片不能用背景路径,只能用网络图片或者base64。
在util中再建立一个chooseimage.js页面
// 本地相册选择图片

wx.chooseImage({

success: res => {

//console.log(res.tempFilePaths[0]);

//读取本地文件内容

wx.getFileSystemManager().readFile({

//要读取的文件的路径

filePath: res.tempFilePaths[0],

// 读取文件的字符编码

encoding: 'base64',//字符编码

success: res => {

console.log(res);

console.log('data:image/jpg;base64,' + res.data);

}

})

}

})

再在背景类bg中调用background:url(本地照片转换的64位base码)


4.获取手机信息:wx.getSystemInfo
在data里先定义好各个手机信息,

data: {

uicon: '../../assets/icons/my.png',

uname: '用户名',

model: '',

system: '',

screenHeight: '',

screenWidth: '',

language: '',

version: ''

}

再wx.getSystemInfo获取手机信息

onLoad: function (options) {

var _this = this;  //function  //function内如果直接用this数据会丢失

// 获取手机系统信息

wx.getSystemInfo({

success: function (res) {  // 回调函数

console.log(res);  //打印出手机信息

_this.setData({  // 将手机各个信息赋值给data里设定的数据,即改变data值,用setData()

model: res.model,

system: res.system,

screenHeight: res.screenHeight,

screenWidth: res.screenWidth,

language:res.language,

version=res.version

})

}

});

wx.getSetting({      //获取授权

success(res) {

if (res.authSetting['scope.userInfo']) {

// 已经授权,可以直接调用 getUserInfo 获取头像昵称

wx.getUserInfo({

success: function (res) {

_this.setData({

uicon: res.userInfo.avatarUrl,

uname: res.userInfo.nickName

})

}

})

} else {

bindGetUserInfo();

}

}

});

},
再在wxml页面调用它例如:  <view>手机型号:{{mobileModel}}</view>

地图定位:
wxml页面:

<map longitude="{{longitude}}"

latitude="{{latitude}}"

polyline="{{polyline}}"

circles='{{circles}}'

scale="13" style='width:100%;height:100%' show-location="true" show-compass="true" enable-rotate="true" enable-traffic="true"
在js页面的data里面定义经度纬度,用setData获取当前定位的经度纬度,再用Poinline定义数组point,存放获取的经度纬度,定义定义的浮标,再在js页面调用show-location="true"显示带有方向的当前定位点。
js页面

onLoad: function () {

console.log(this)

},

onReady: function () {

var _this = this;

wx.getLocation({

success: function (res) {

console.log(res);

_this.setData({

longitude: res.longitude,

latitude: res.latitude,

 

})

_this.setData({

latitude: res.latitude,

longitude: res.longitude,

polyline: [{

points: [{

latitude: res.latitude,

longitude: res.longitude,

}],

color: "#FF0000DD",

width: 2,

dottedLine: true

}],
|显示结果:

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值