需要获取某一个城市的天气情况需要三步,先创建key,在获取当前城市位置,最后用获取到的城市换取当地天气 1.先创建一个高德key,在选择类型时选择web服务 地址console.amap.com/dev/key/app
2.调用高德api获取当前城市ip lbs.amap.com/api/webserv…
const getCtiy = async () => {
await axios.get('restapi.amap.com/v3/ip?key='… => {
if(res.data.status === '1') {
getWeatherInfo(res.data.adcode);
}
}).catch(( err ) => {
})
};
3.拿获取到的城市ip再去获取天气 lbs.amap.com/api/webserv… const getWeatherInfo = async (city: any) => { await axios.get('restapi.amap.com/v3/weather/…' + city + '&key='+ '你的key').then((res) => { if (res.data.status === '1') { 这里的结果将是你需要的天气情况 } }).catch((err) => { console.log('err', err) }); }