wx.getLocation定位
发布于 5 年前 作者 jkong 3276 次浏览 来自 问答

再次授权定位。返回后不执行wx.getLocation方法,获取不到定位

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) {//非初始化进入该页面,且未授权

console.log(“没授权”)

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

})

//再次授权,调用getLocationt的API

that.posit(that);

} else {

wx.showToast({

title: ‘授权失败’,

icon: ‘success’,

duration: 5000

})

}

}

})

}

}

})

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

that.posit(that);

}

}

})

}

在开发工具上是执行wx.getLocation方法的,在手机上就不执行

3 回复

返回不执行onReady方法,还有wx.openSetting()即将废弃,请尽早适配。

赞我。。。

你这个看得头晕脑胀的,搞得怎么复杂~

//请求定位授权

dingwei: function() {

var that = this;

wx.authorize({

scope: ‘scope.userLocation’,

success() {

wx.getSetting({

success(res) {

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

that.setData({

dingwei: true,

})

that.login();

}

}

})

},

fail: function() {

that.setData({

dingwei: false,

})

}

})

},

dingwei: false,时将显示重新授权框,点击按钮打开设置!

fail是因为没网络的情况下怎么写都一样,白搭。

是不执行onReady方法,成功后又调用了that.posit(that);

回到顶部