逆地址解析
wx.getLocation
获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用。开启高精度定位,接口耗时会增加,可指定 highAccuracyExpireTime 作为超时时间。地图相关使用的坐标格式应为 gcj02。
<button bindtap="getAddress">获取地理位置</button>
Page({
getAddress(){
wx.getLocation({ //没有特别说明的都是固定写法
type: 'wgs84',
success: function (res) {
console.log('location', res);
var locationString = res.latitude + "," + res.longitude;
wx.request({
url: 'http://apis.map.qq.com/ws/geocoder/v1/',
data: {
"key": "*****-4SFCR-*****-W4IZ3-*****-2WF35",
"location": locationString
},
method: 'GET',
success: function (r) {
//输出一下位置信息
console.log(r);
}
});
}
});
}
})
解析效果
点击button按钮,就可以在控制台查看
代码中用到的key,需要去申请一个。
腾讯位置服务:https://lbs.qq.com/
登录之后,进入个人主页,【应用管理】>>【我的应用】申请一个key