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

报错如下:

解决方案:

一、uniapp项目

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

代码如下:

 /* 小程序特有相关 */
    "mp-weixin" : {
        "appid" : "",
        "setting" : {
            "urlCheck" : false
        },
		 "usingComponents" : true,
		"permission": {
		    "scope.userLocation": {
		      "desc": "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位
		    }
		  },
	   "requiredPrivateInfos": [ "getLocation", "onLocationChange"]
    },

 微信小程序会自动同步配置

 代码如下:

},
  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序位置接口的效果展示"
    }
  },
  "requiredPrivateInfos": [
    "getLocation",
    "onLocationChange"
  ],

猜你喜欢

转载自blog.csdn.net/xm1037782843/article/details/129350506