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

您所在的位置:网站首页 微信小程序json 解决微信小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json

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

2024-07-12 00:17| 来源: 网络整理| 查看: 265

报错如下:

解决方案:

一、uniapp项目

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

 光上图,不上代码的,不是好司机。

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

二、原生小程序

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

{ "pages": ["pages/index/index"], "permission": { "scope.userLocation": { "desc": "你的位置信息将用于小程序位置接口的效果展示" }, "scope.userFuzzyLocation": { "desc": "你的位置信息将用于小程序位置接口的效果展示" } }, "requiredPrivateInfos": ["chooseLocation", "getFuzzyLocation"] }

requiredPrivateInfos的配置扩展: 

注意事项:

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

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

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

附:微信公众平台,开通定位接口姿势:开通定位接口 

友情提示:修改代码之后,如果不生效,一定要重新编译! 重新编译! 重新编译! 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3