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

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

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

报错如下:


"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” 的相关文章

js中对象属性值排序(字典倒排序)

js中对象属性值排序(字典倒排序)

sort函数实用于数组不适用于对象先说一下sort函数:var a=[3,2,5,7,3,6,8,9,1,2]; document.writeln(a.sort());12结果即是对a顺序排序;逆序排序两种方法,第一种:docu…

php高效检测远程图片是否存在

php高效检测远程图片是否存在function img_exits($url){     $ch = curl_init();    &…

[Windows] Adobe Flash Player 34.0.0.92及可用版修改方法

[Windows] Adobe Flash Player 34.0.0.92及可用版修改方法

随着 2021 年的到来,Adobe Flash Player 也迎来了告别,Adobe 在 2020 年 12 月 31 日后将不再支持 Flash Player。其实早在 2017 年,Adobe 公司就已宣布,计划在 2020 年底逐…

[教程] WTG备份新方法——FFU镜像格式

[教程] WTG备份新方法——FFU镜像格式

FFU(Full Flash Update) 格式是一种基于扇区的磁盘镜像文件格式,默认使用快速哈夫曼压缩(Xpress-Huffman)算法压缩,在捕获和部署时会生成哈希表进行校验,并可以使用DISM修改捕获的镜像。FFU格式很适合WTG…

VirtualXposed 不支持32位应用 32位无法安装问题解决办法

VirtualXposed 不支持32位应用 32位无法安装问题解决办法

VirtualXposed 是基于VirtualApp 和 epic 在非ROOT环境下运行Xposed模块的实现(支持5.0~10.0)。与 Xposed 相比,目前 VirtualXposed 有…

PIP 更换国内安装源linux/windows

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

发表评论

访客

看不清,换一张

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