【发布时间】: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