You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
1.5 KiB

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;
let _c = info.ad_info.adcode.slice(0,3)
location.cityId = info.ad_info.city_code.slice(3);
location.provinceId = _c.padEnd(6,'0');
location.areaId = info.ad_info.adcode;
location.province = info.address_component.province;
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,
};