赞
踩
前提:uniapp的wx小程序项目,接手别人的老项目,getLocation时开发者工具报未授权,顺着授权步骤走却发现已经授权了。已经上线的小程序没问题。遇到有段时间了,今天有时间看看:
如上图:明明已经授权了
排查流程:
1.uni.authorize()查询是否已授权
- uni.authorize({
- scope:'scope.userLocation',
- success: (res) => {
- console.log('authorize=>success:',res);
- },
- fail: (err) => {
- console.log('authorize=>fail:',fail);
- }
- },)
结果:
2.查看getLocation()的报错信息
- uni.getLocation({
- type: 'wgs84',
- success: function(result) {
- successBack(result)
- },
- fail: function(error) {
- console.log('getLocation=>fail:',error);
-
- 。。。。。。。。。
- }
结果:
需要在requiredPrivateInfos字段中声明
百度报错信息得知:地理位置接口新增与相关流程调整 | 微信开放社区 (qq.com)
新的接口除了要申请接口外还要在uniapp的manifest.json中配置
- "permission" : {
- "scope.userLocation" : {
- "desc" : "你的位置信息将用于小程序位置接口的效果展示"
- }
- },
- "requiredPrivateInfos":["getLocation"],
就可以了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。