一、配置manifest.json
示意图二、腾讯位置服务平台申请密钥并下载SDK(详细文档)
三、代码接入
1.导入下载的sdk
import QQMapWX from "../services/sdk/qqmap-wx-jssdk.min.js";
2.获取位置信息的方法
//获取位置信息
async 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: 'xxxxxxxxxx' //申请的key
});
qqmapsdk.reverseGeocoder({
location,
success(response) {
let info = response.result;
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(err) {
resolve(location);
},
});
});
},
3.调用方法
async onLoad() {
//获取地理位置
const location = await this.getLocationInfo();
},
4.返回的数据结构
网友评论