微信小程序根据经纬度请求本地天气接口
onLoad: function (options) {
wx.getLocation({
success: ({ latitude, longitude }) => {
wx.request({
url: 'http://www.test.com/wx/interface/setup/weather.php', //天气接口地址
data: {
x: latitude,
y: longitude
},
header: {//请求头
"Content-Type": "application/x-www-form-urlencoded"
},
method: "GET",
success: (res) => {
console.log(res.data)
let weather = res.data.data
console.log(weather)
this.setData({ weather })
},
})
}
})
}