我使用开放天气api来显示天气,但我需要显示多个位置的天气。有什么建议吗?
function getWeather(callback) {
var weather = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=Zagreb&&APPID=08dbab0eeefe53317d2e0ad7c2a2e060';
$.ajax({
dataType: "jsonp",
url: weather,
success: callback
});
}这就是我如何显示一个城市的天气,但我不知道如何通过更多的城市?!
发布于 2017-12-20 12:33:53
您需要获取想要调用的每个城市的id,可以在以下位置找到:
http://bulk.openweathermap.org/sample/city.list.us.json.gz http://bulk.openweathermap.org/sample/city.list.json.gz
然后,根据这里的https://openweathermap.org/current#severalid接口文档,您可以使用以下代码一次调用多个城市的数据:
http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metrichttps://stackoverflow.com/questions/38661588
复制相似问题