用户2877307
用户2877307
  • 发布:2025-08-26 18:07
  • 更新:2025-08-26 18:14
  • 阅读:14

uni.getLocatoin报错"getLocation:fail Cannot read properties of undefined (reading 'then')"

分类:uni-app

代码如下:

const [err, loc] = await uni.getLocation({  
                    type: 'gcj02'  
                });  
                if (err) {  
                    console.log(err)  
                } 

返回err,打印如下:
“{ "errMsg": "getLocation:fail Cannot read properties of undefined (reading 'then')" }”

初学者,请教大神指点,多谢!

2025-08-26 18:07 负责人:无 分享
已邀请:
爱豆豆

爱豆豆 - 办法总比困难多

getLocation不是Promise对象
可以用成功回调获取到返回数据

uni.getLocation({  
            type: 'wgs84',  
            success: function (res) {  
                console.log('当前位置的经度:' + res.longitude);  
                console.log('当前位置的纬度:' + res.latitude);  
            }  
})

参考文档:https://uniapp.dcloud.net.cn/api/location/location.html

要回复问题请先登录注册