我正想开发一个打车的小程序,需要对用户精确定位,如果用户都没有开启手机上的位置信息,是没办法精确定位的。那么该如何知道用户是否开启了位置信息,或者能自动给他打开更好。
首先有这个几种情况:①用户正常授权,可以获取;②用户之前授权了,手动在设置里关闭了授权,不可以获取;③用户拒绝授权,不可以获取;④用户不管授权与否,手机系统位置信息定位权限没开,不可以获取。
看看这个https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.getLocation.html
// 判断用户是否授权 wx.getSetting({ success: (res) => { var statu = res.authSetting; if (!statu['scope.userLocation']) { //没授权 wx.showModal({ title: '是否授权当前位置', content: '需要获取您的地理位置,请确认授权', confirmColor: '#f16765', success: res => { if (res.confirm) { wx.openSetting({ success: data => { if (data.authSetting["scope.userLocation"]) { // 地图,获取位置信息(就是经纬度转换成地址) this.xx() } } }) } } }) } else { //已授权 } } })