getLocation定位失败 requiredPrivateInfos

2,448 阅读1分钟

问题:小程序调用收货地址 API 报错:errMsg: "chooseAddress:fail the api need to be declared in …e requiredPrivateInfos field in app.json/ext.json",导致无法弹出选择收货地址界面

image.png

原因:小程序发生了定位失败的情况

解决方案:

一、unipp项目

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

  "mp-weixin": {
    /* 小程序特有相关 */
    "appid": "wx732b638fe29ac10a",
    "setting": {
      "urlCheck": true,
      "es6": true,
      "postcss": true,
      "minified": true
    },
    "usingComponents": true,
    "permission": {
      "scope.userLocation": {
        "desc": "你的位置信息将用于小程序位置接口的效果展示"
      }
    },
    "requiredPrivateInfos": [
      "chooseAddress",
      "chooseLocation",
      "choosePoi",
      "getLocation",
      "onLocationChange",
      "startLocationUpdateBackground",
      "startLocationUpdate"
    ]
  },

二、原生小程序

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

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