用户已经授权位置,手机定位正常,但是调用:wx.getLocation返回:fail
onLoad: function (options) {
var that=this
wx.authorize({
scope:'scope.userLocation',
success:function(e){
console.log(e)
console.log('用户位置授权成功');
wx.getLocation({
type: 'jcg02',
success(res) {
var latitude = res.latitude;
var longitude = res.longitude;
console.log('latitude' + latitude)
console.log('longitude' + longitude)
that.setData({
latitude: latitude,
longitude: longitude
})
},
fail:function(e){
console.log('调用getLocation失败')
console.log(e)
}
})
}
})
}
2 回复
onLoad: function(options) {
var that = this
wx.showModal({
title: '是否授权当前位置',
content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
success: function(tip) {
if (tip.confirm) {
wx.openSetting({
success: function(data) {
if (data.authSetting["scope.userLocation"] === true) {
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
//授权成功之后,再调用chooseLocation选择地方
wx.getLocation({
type: 'jcg02',
success(res) {
var latitude = res.latitude;
var longitude = res.longitude;
console.log('latitude' + latitude)
console.log('longitude' + longitude)
that.setData({
latitude: latitude,
longitude: longitude
})
},
fail: function(e) {
console.log('调用getLocation失败')
console.log(e)
}
})
} else {
wx.showToast({
title: '授权失败',
icon: 'success',
duration: 1000
})
}
}
})
}
}
})
}