获取当前位置
写一个button,给个点击事件,先调用wx.getLocation,获取当前的经纬度,type类型为gcj02,在成功回调里调用wx.openLocation,参数填上经纬度,再在成功回调里调用wx.chooseLocation来选择当前位置(点击确定后)打印当前位置信息。
<button bindtap="getLocation">获取当前位置</button>
getLocation() {
wx.getLocation({
type: 'gcj02',
success:function(res){
console.log(res)
wx.openLocation({
latitude: res.latitude,
longitude: res.longitude,
success:function(res){
console.log(res)
wx.chooseLocation({
success:function(res){
console.log(res)
}
})
}
})
}
})
},
电脑上定位有偏差,建议手机调试
关于手机上点击按钮一直没反应
手机没开定位请打开手机定位 :)
不要问我怎么会有这个问题 :)
如果出现
在app.js里面添加
即可