<button bindtap='getLocation' type='primary'>获取当前位置</button>
getLocation:function(){
wx.getLocation({
type:'gcj02',
success: function(res) {
console.log(res);
wx.openLocation({
latitude: res.latitude,
longitude: res.longitude,
scale:17, //5-18
success:function(res){
wx.chooseLocation({
success: function(res) {
console.log(res);
},
})
}
})
},
fail:function(err){
console.log(err)
}
})
},
记得在app.json中加上:
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},