Taro Error: MiniProgramError {“errMsg“:“getLocation:fail

2022/9/22

taro版本已经更新了

在这里插入图片描述
报错信息
在这里插入图片描述

Error: MiniProgramError
{"errMsg":"getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json"}
    at Object.errorReport (WAServiceMainContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at Function.thirdErrorReport (WAServiceMainContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at Object.thirdErrorReport (WAServiceMainContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at a (WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at Object.cb (WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at H._privEmit (WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at H.emit (WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1
    at Pe (WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1)
    at WASubContext.js?t=wechat&s=1663850492189&v=2.26.1:1(env: Windows,mp,1.06.2209190; lib: 2.26.1)

Taro.getLocation() 使用报错

是这么使用的

 Taro.getLocation({
            type: 'wgs84',
            success: function (res) {
                setArdessInfo(res)
                console.log(res)
            },
            fail:function(e){
                console.log(e)
            },
            complete:function(){
                fetch()
            }
        })

app.config.js

 permission: {
    'scope.userLocation': {
      desc: '你的位置信息将用于小程序位置接口的效果展示'
    }
  },

以上是我的使用方式,下面说解决方法。

app.config.js 添加一些配置,

 permission: {
    'scope.userLocation': {
      desc: '你的位置信息将用于小程序位置接口的效果展示'
    }
  },


  "requiredBackgroundModes": ["audio", "location"],
  "requiredPrivateInfos": ["getLocation"],

到这可能就解决了。

在这里插入图片描述

或者这行报错,添加这句可以解决。

 requiredPrivateInfos?: ('getFuzzyLocation' | 'getLocation' | 'onLocationChange' | 'startLocationUpdate' | 'startLocationUpdateBackground' | 'chooseLocation' | 'choosePoi' | 'chooseAddress')[] 

在这里插入图片描述
然后就不报错了,经纬度也获取到了,uniapp如果报错也应该可以按照这个思路试一试 。
在这里插入图片描述
在这里插入图片描述

参考
https://github.com/NervJS/taro/pull/12099/commits/97aa1041ad7b947bf61b264b15c65bae5a36b419

https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#requiredPrivateInfos

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值