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