高德天气获取
访问高德官网,控制台,应用,创建新应用,高德开放平台 | 高德地图API (amap.com)
接口文档:
定位接口:IP定位-API文档| 高德地图API
天气预报接口:天气查询-API文档 | 高德地图API
我这里会报跨域的错,找了很多方法没解决,最后用了一个简单的方法
const [weather, setWeather] = useState({});useEffect(() => {fetch('https://restapi.amap.com/v3/weather/weatherInfo?city=370104&key=你的key').then(response => response.json()).then(data => {if (data.status === '1') {setWeather(data.lives[0]);console.log(data.lives[0]);} else {console.error('Failed to fetch weather data:', data.info);}}).catch(error => {console.error('Error fetching data:', error);});}, []);