小程序调用地图
https://developers.weixin.qq.com/community/develop/article/doc/00068a6ce50718e82f1c1d75650013
上方调用地图虽然好用好看但是会出现bug,比如回显的数据无法被清除修改,所以我改用为wx.chooseLocation(Object Object)方法
// 需要注意的是 当用户拒绝定位授权后,此后每次调用都走fail() ,导致没办法再次弹出授权框 ,所以需要自己定义一个再次开启权限的方法
getLocation: function () {
var _this = this;
wx.chooseLocation({
success: function (res) {
var name = res.name
var address = res.address
_this.setData({
address: address + name,
latitude: res.latitude,
longitude: res.longitude
})
_this.findShop() //计算距离
},
fail:function(params) {
_this.fetchAgainLocation()
},
complete(r){
console.log(r)
console.log(222)
}
})
},
// 当用户拒绝授权定位后,再次点击调用此方法,开启定位权限
fetchAgainLocation() {
let that = this
wx.getSetting({
success: (res) => {
var statu = res.authSetting;
if (!statu['scope.userLocation']) {
wx.showModal({
title: '是否授权当前位置',
content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
success: (tip) => {
if (tip.confirm) {
wx.openSetting({
success: (data) => {
if (data.authSetting["scope.userLocation"] === true) {
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
wx.chooseLocation({
success: res => {
console.log('打开地图选择确定', res)
}
})
} else {
wx.showToast({
title: '授权失败',
icon: 'success',
duration: 1000
})
}
},
fail: () => {},
complete: () => {}
});
}
}
})
}
},
fail: ()=>{},
complete: ()=>{}
})
}
————————————————
原文链接:https://blog.csdn.net/qq_41357391/article/details/102783290

浙公网安备 33010602011771号