https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html
新授权获取用户信息
js
onGetUserInfo(e){
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
map地图的使用
json
1.在app.json中添加
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
js
2.调用地理定位接口
wx.getLocation({
type: 'gcj02',
success: function (res) {
console.log(res);
}
});
返回值
accuracy: 65
buildingId: ""
direction: -1
errMsg: "getLocation:ok"
floorName: "1000"
horizontalAccuracy: 65
latitude: 34.82350540161133
longitude: 113.64183807373047
provider: "gps"
speed: -1
verticalAccuracy: 10
html
3.地图组件 (需要用getLocation获取经纬度)
<map longitude="{{longitude}}" latitude="{{latitude}}"></map>
微信小程序之逆地址解析
同地图的显示,需要配置app.json中的permission
onLoad: function () {
let self = this;
wx.getLocation({
type: 'gcj02',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
console.log(latitude, longitude);
let key = "6ESBZ-MQECU-BVFVV-4O5A3-J3ZH2-OUBDU"
self.getCityInfo(latitude, longitude, key)
},
fail(error) {
throw new Error("获取位置信息失败...")
}
})
},
getCityInfo(lat, lng, mapKey, callback) {
let self = this;
// 逆位置解析
// https://lbs.qq.com/webservice_v1/guide-gcoder.html
wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=${mapKey}`,
success: res => {
console.log(res.data.result);
}
})
}