import QQMapWX from '@/libs/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js'; //获取位置信息 async function getLocationInfo() { return new Promise((resolve) => { //位置信息默认数据 let location = { longitude: 0, latitude: 0, province: '', city: '', area: '', street: '', address: '', }; uni.getLocation({ type: 'gcj02', success(res) { location.longitude = res.longitude; location.latitude = res.latitude; // 腾讯地图Api const qqmapsdk = new QQMapWX({ key: 'X5YBZ-ES6K3-Q6E3P-RUVXH-2R5ZQ-ERBFG', //这里填写自己申请的key }); qqmapsdk.reverseGeocoder({ location, success(response) { console.log(response) let info = response.result; location.province = info.address_component.province; location.cityCode = info.ad_info.city_code.slice(3); location.city = info.address_component.city; location.area = info.address_component.district; location.street = info.address_component.street; location.address = info.address; resolve(location); }, fail(e){ console.log(e,'地址信息报错') } }); }, fail(err) { console.log(err); resolve(location); }, }); }); } //导出 module.exports = { getLocationInfo, };