//已知的经纬度
var latitude = this.data.latitude;
var longitude = this.data.longitude
var key = 'FK4BZ-VQSCK-XQGJQ-AUH4M-MXST3-OLFQQ' //写自己申请的key
wx.getLocation({
success: function (res) {
wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
success: function (res) {
console.log(res);
//根据自己项目需求获取res内容
var addresscity = res.data.result.address_component.city
if (addresscity.indexOf('市') !== -1) { //这里是去掉“市”这个字
addresscity = addresscity.slice(0, addresscity.indexOf('市'));
console.log(addresscity);
}
wx.setStorageSync('locationCity', addresscity)
that.setData({
addresscity: addresscity
});
}
})
},
})
打印请求到的res