【问题标题】:Open Weather Api multiple locations?打开 Weather Api 多个位置?
【发布时间】:2016-12-04 08:01:47
【问题描述】:

我正在使用开放天气 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
    });
}

这是我只显示一个城市的天气,但我不知道如何通过更多城市?!

【问题讨论】:

  • 有多少个地点?是否会添加其他位置?
  • 我需要 8 个位置...是的,它们将被添加,我需要显示它们
  • 如果用户不多,您可以进行 8 种不同的查询。如果有很多用户,我会将这些信息存储在某个地方以减少查询量,然后从存储的信息中查询(当然是在有限的时间内)

标签: jquery openweathermap


【解决方案1】:

您需要为每个要呼叫的人获取城市 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 找到的 API 文档,您可以使用以下代码一次调用多个城市的数据:

http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric

【讨论】:

    猜你喜欢
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 2017-07-19
    相关资源
    最近更新 更多