wx.getLocation 在安卓系统中获取不到定位权限
发布于 6 年前 作者 qiang03 14004 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现

res.authSetting[‘scope.userLocation’] 的值不能为undefine,应当为true或者false , 或者调用wx.getLocation能够定位。

目前在IOS系统中可以。

安卓手机也出现过可以的情况,不稳定,真机调试。

  • 复现路径
  • 提供一个最简复现 Demo

Page({

onLoad:function(option){

var that =this;

village_LBS(that);

},

onReady:function(){

var that = this;

wx.getSetting({

success:(res)=>{

console.log(res);

console.log(res.authSetting[‘scope.userLocation’]);

if (res.authSetting[‘scope.userLocation’] != undefined && res.authSetting[‘scope.userLocation’] != true){

wx.showModal({

title: ‘是否授权当前位置’,

content: ‘需要获取您的地理位置,请确认授权,否则地图功能将无法使用’,

success:function(res){

if (res.cancel) {

console.info(“1授权失败返回数据”);

}

else if (res.confirm){

wx.openSetting({

success: function (data){

console.log(data);

if(data.authSetting[“scope.userLocation”] == true){

wx.showToast({

title: ‘授权成功’,

icon:‘success’,

duration:5000

})

village_LBS(that);

}

}

})

}

}

})

}

else if (res.authSetting[‘scope.userLocation’] == true) {//初始化进入

village_LBS(that);

}

else if (res.authSetting[‘scope.userLocation’] == undefined){

}

}

})

}

})

// 地图功能单独拿出来 - xzz1023

var village_LBS = function (that) {

wx.getLocation({

type:‘gcj02’,

success:function(res){

console.log(res.latitude);

console.log(res.longitude);

}

})

}

1 回复

已经解决了

回到顶部