对于微信小程序的api文件只能获取坐标数据,代码如下:
wx.getLocation({
success: res => {
console.log("位置信息:" + res.latitude);
this.setData({
myLoacltion: res,
startPoint: {
name: "我的位置",
latitude: res.latitude,
longitude: res.longitude
},
})
},
})
当拿到坐标数据之后,通过腾讯地图的地理逆向编码请求拿到具体的地址信息:
sendRequest: function (qqMapApi) {
const that = this
wx.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/' + "?location=" + res.latitude + ',' +
res.longitude + "&key=您的key" &get_poi=1"
,
header: {
'Content-Type': 'application/json'
},
data: {},
method: 'GET',
success: (res) => {
console.log(res.data)
that.setData({
myaddress: res.data.result.address,//获取的具体的坐标数据
});
}
})
},