首先我们是需要调用微信 wx.getLocation({}) 获取到用户 坐标位置
onLoad(){
var that = this;
var BMap = new bmap.BMapWX({
ak: app.globalData.ak
});
wx.getLocation({
type: 'gcj02', //重点就是在这里
success: function (res) {
console.log(res,97)
BMap.regeocoding({
location: res.latitude + ',' + res.longitude,
success: function (res) {
console.log(res)
wxMarkerData = res.wxMarkerData;
app.globalData.loactioninfo = res
app.globalData.LocateName = res.originalData.result.sematic_description
that.setData({
LocateName: res.originalData.result.sematic_description
})
},
fail: function () {
wx.showToast({
title: '请检查位置服务是否开启',
})
},
});
},
fail: function () {
console.log('小程序得到坐标失败')
}
})
},
因为type属性有三个类型,如果是百度地图我们要选gcj02即可 这样解析出来的地址是没有误差的
亲测只需修改type即可,有帮助的小伙伴记得关注!
喜欢上方小程序,需要源码的,私信小编留下邮箱。