当前位置:首页 > 技术分享

解决小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json

admin4年前 (2022-11-07)技术分享6812

报错如下:


"getLocation:fail the api need to be declared in the requiredPrivateInfos fi


解决方案:


一、unipp项目


打开uniapp项目的配置文件manifest.json,选择“源码视图”。


/* 小程序特有相关 */

"mp-weixin": {
	"appid": "你的开发者id",
	"setting": {
		"urlCheck": true,
		"es6": true,
		"postcss": true,
		"minified": true
	},
	"usingComponents": true,
	"permission": {
		"scope.userLocation": {
			"desc": "你的位置信息将用于小程序位置接口的效果展示"
		}
	},
	"requiredPrivateInfos": [
		"getLocation"
	]
},

二、原生小程序


打开项目的配置文件app.json。

{
    "pages": ["pages/index/index"],
    "permission": {
        "scope.userLocation": {
            "desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
        }
    },
    "requiredPrivateInfos": [
		"getLocation"
	]
}

requiredPrivateInfos的配置扩展: 


表1中模糊位置信息(序号1)和精确位置信息(序号2-5)是互斥的,即声明了模糊位置信息就无法声明精确位置信息。


若同时声明模糊位置信息和精确位置信息,则在编译代码时出现错误;


更多文档,请参考官方文档:地理位置接口新增与相关流程调整 

扫描二维码推送至手机访问。

版权声明:本文由小刚刚技术博客发布,如需转载请注明出处。

本文链接:https://blog.bitefu.net/post/446.html

分享给朋友:

“解决小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json” 的相关文章

mysql 数据表中查找重复记录

select [user_name],count(*) as count from [user_table] group by [user_name] having count>1; user_name 要查重复记录的字段u…

解决 SVN Skipped 'xxx' -- Node remains in conflict

更新命令:svn up提示代码:意思就是说 ,这个文件冲突了,你要解决下Updating '.': Skipped 'data/config.php' -- …

安装Windows 10X 教你如何安装Win10X正式版 及下载地址

安装Windows 10X 教你如何安装Win10X正式版 及下载地址

安装Windows 10X 教你如何安装Win10X正式版:Windows 10X是Windows 10操作系统的新版本,主要针对双屏电脑。由于即将运行Windows 10X的双屏电脑(例如即将面世的Surface Neo)的开发遇到挫折,…

PIP 更换国内安装源linux/windows

pip国内的一些镜像  阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/   豆瓣(…

七牛html js上传带进度条源码

七牛html js上传带进度条源码注册链接https://s.qiniu.com/uM7RJv完整代码下载:https://n802.com/f/349707-489018989-c141f6(访问密码:5036)http://www.yi…

apicloud影视APP源码 无需后台

apicloud影视APP源码 无需后台

介绍集合vip影视接口到一个android app中 方便观看各平台影视资源及直播开源地址:https://gitee.com/web/vip_yingshi软件架构使用apicloud搭建影视APP源码,无后台,调用接口同步api解析网址…

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。