描述
获取当前定位的经纬度后使用 逆地址解析 获取到详细的地址
uniapp和微信小程序获取地址有两个API,getLocation和chooseLocation,但都没有返回省市区等具体信息,那我们可以获取当前经纬度,然后使用逆地址解析接口去获取更多信息
逆地址解析概述
使用步骤
1.前往腾讯位置服务官网 申请key
https://lbs.qq.com/dev/console/user/info
填写自己小程序的appid
2.使用
是的,拿到key之后就可以在项目中使用了
uni.getLocation({
type: 'wgs84',
isHighAccuracy:true, //开启高精度定位
success: (res)=> {
console.log('当前位置的经纬度:' ,res.longitude, res.latitude);
uni.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=${key}`,
data: {},
success: (res2) => {
console.log(res2);
}
});
}
});
请求url
https://apis.map.qq.com/ws/geocoder/v1/?location=
r
e
s
.
l
a
t
i
t
u
d
e
,
{res.latitude},
res.latitude,{res.longitude}&key=${key}
https://apis.map.qq.com/ws/geocoder/v1/ :固定的请求地址,为GET请求
参数
location:格式 location=纬度,经度
key:是自己创建的
更多请求参数及返回接口请查看
https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder#5