0
点赞
收藏
分享

微信扫一扫

uniapp 小程序中使用逆地址解析 获取当前详细地址

小迁不秃头 2022-01-13 阅读 68

描述

获取当前定位的经纬度后使用 逆地址解析 获取到详细的地址
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
在这里插入图片描述

举报

相关推荐

0 条评论