【问题标题】:Where to find OpenWeatherMap jar?在哪里可以找到 OpenWeatherMap jar?
【发布时间】:2017-06-24 03:46:46
【问题描述】:

我想创建 java 天气应用程序。

我有来自 Open Weather 的代码和 API,但我没有 jar 文件。

这是我的代码

public class WeatherTest {

    public static final void main(String[] args) {
        boolean isMetric = true;
        String owmApiKey = "XXXXXXXXXXXX";

        /* YOUR OWM API KEY HERE */
        String weatherCity = "Brisbane,AU";
        byte forecastDays = 3;
        OpenWeatherMap.Units units = (isMetric)
            ? OpenWeatherMap.Units.METRIC
            : OpenWeatherMap.Units.IMPERIAL;
        OpenWeatherMap owm = new OpenWeatherMap(units, owmApiKey);
        try {
            DailyForecast forecast = owm.dailyForecastByCityName(weatherCity, forecastDays);
            System.out.println("Weather for: " + forecast.getCityInstance().getCityName());
            int numForecasts = forecast.getForecastCount();

            for (int i = 0; i < numForecasts; i++) {
                DailyForecast.Forecast dayForecast = forecast.getForecastInstance(i);
                DailyForecast.Forecast.Temperature temperature = dayForecast.getTemperatureInstance();
                System.out.println("\t" + dayForecast.getDateTime());
                System.out.println("\tTemperature: " + temperature.getMinimumTemperature()
                    + " to " + temperature.getMaximumTemperature() + "\n");
            }
        } catch (IOException | JSONException e) {
        e.printStackTrace();
        }
    }
}

【问题讨论】:

  • 你指的jar文件是什么。 OpenWeatherMap 提供了一个 REST API,您可以调用它来获取数据
  • 怎么样?你能帮帮我吗?

标签: java openweathermap


【解决方案1】:

OpenWeatherMap 提供了一个 REST API,您可以调用它来获取天气数据。 API规范请参考https://openweathermap.org/api

为了使用 Java 代码调用它,您必须实现一个 REST Java 客户端。有很多方法可以做到这一点,但作为一个开始,你可以参考https://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

另外,还有许多围绕 OpenWeatherMap API 开发的客户端。您可以通过https://github.com/search?p=1&q=openweathermap&ref=cmdform&type=Repositories 搜索它们

既然你在找Java,我建议你看看https://github.com/xSAVIKx/openweathermap-java-api

https://github.com/xSAVIKx/openweathermap-java-api/blob/master/api-examples/src/main/java/org/openweathermap/api/example/DailyForecastExample.java 提供了此库的示例

【讨论】:

    猜你喜欢
    • 2022-11-03
    • 1970-01-01
    • 2012-06-14
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    相关资源
    最近更新 更多