在 OWM-JAPI 中获取天气
Getting weather in OWM-JAPI
我正在使用 OWM-JAPI (https://github.com/iamashks/OWM-JAPIs) 在 Java 上编写天气应用程序。
正在尝试获取天气信息(如晴天、多云等),但我遇到了一些问题。
getCity().getWeatherList()
显示[Weather(conditionId=801, mainInfo=Clouds, moreInfo=небольшая облачность, iconCode=02d)]
我需要在 moreInfo
中获取信息。
我该怎么做?谢谢。
P.S。如果您需要,我可以在 github 上向您发送我的所有项目。
这是我的代码:
import net.aksingh.owmjapis.core.OWM;
import net.aksingh.owmjapis.api.APIException;
import net.aksingh.owmjapis.model.CurrentWeather;
public class Main {
// configure owm: api key, lang, accuracy, etc
private static OWM config(){
OWM owm;
owm = new OWM("061c88a24ac0ad18ae22534accea424a");
owm.setUnit(OWM.Unit.METRIC);
owm.setLanguage(OWM.Language.RUSSIAN);
owm.setAccuracy(OWM.Accuracy.ACCURATE);
return owm;
}
// getting city class
private static CurrentWeather getCity() throws APIException {
CurrentWeather cwd;
cwd = config().currentWeatherByCityName("Stupino");
return cwd;
}
// getting temperature
private static int getTemperature() throws APIException, NullPointerException{
int temp;
temp = (int)Math.round(getCity().getMainData().getTemp());
return temp;
}
// getting weather time
private static String getTime() throws APIException {
String time;
int hours, minutes, seconds;
hours = getCity().getDateTime().getHours();
minutes = getCity().getDateTime().getMinutes();
seconds = getCity().getDateTime().getSeconds();
time = hours + ":" + minutes + ":" + seconds + ".";
return time;
}
// sending weather info to user
private static void message() throws APIException {
String msgTime, msgCity, msgTemp, msgWeather;
msgTime = "Погода на " + getTime();
msgCity = "Город: " + getCity().getCityName();
msgTemp = "Температура: " + getTemperature() + "°C.";
System.out.println(msgTime + "\n" +
msgCity + "\n" +
msgTemp);
}
public static void main(String[] args) throws APIException, NullPointerException{
message();
}
}
调用获取列表第一个元素的更多信息:
getCity().getWeatherList().get(0).getMoreInfo()
我正在使用 OWM-JAPI (https://github.com/iamashks/OWM-JAPIs) 在 Java 上编写天气应用程序。 正在尝试获取天气信息(如晴天、多云等),但我遇到了一些问题。
getCity().getWeatherList()
显示[Weather(conditionId=801, mainInfo=Clouds, moreInfo=небольшая облачность, iconCode=02d)]
我需要在 moreInfo
中获取信息。
我该怎么做?谢谢。
P.S。如果您需要,我可以在 github 上向您发送我的所有项目。
这是我的代码:
import net.aksingh.owmjapis.core.OWM;
import net.aksingh.owmjapis.api.APIException;
import net.aksingh.owmjapis.model.CurrentWeather;
public class Main {
// configure owm: api key, lang, accuracy, etc
private static OWM config(){
OWM owm;
owm = new OWM("061c88a24ac0ad18ae22534accea424a");
owm.setUnit(OWM.Unit.METRIC);
owm.setLanguage(OWM.Language.RUSSIAN);
owm.setAccuracy(OWM.Accuracy.ACCURATE);
return owm;
}
// getting city class
private static CurrentWeather getCity() throws APIException {
CurrentWeather cwd;
cwd = config().currentWeatherByCityName("Stupino");
return cwd;
}
// getting temperature
private static int getTemperature() throws APIException, NullPointerException{
int temp;
temp = (int)Math.round(getCity().getMainData().getTemp());
return temp;
}
// getting weather time
private static String getTime() throws APIException {
String time;
int hours, minutes, seconds;
hours = getCity().getDateTime().getHours();
minutes = getCity().getDateTime().getMinutes();
seconds = getCity().getDateTime().getSeconds();
time = hours + ":" + minutes + ":" + seconds + ".";
return time;
}
// sending weather info to user
private static void message() throws APIException {
String msgTime, msgCity, msgTemp, msgWeather;
msgTime = "Погода на " + getTime();
msgCity = "Город: " + getCity().getCityName();
msgTemp = "Температура: " + getTemperature() + "°C.";
System.out.println(msgTime + "\n" +
msgCity + "\n" +
msgTemp);
}
public static void main(String[] args) throws APIException, NullPointerException{
message();
}
}
调用获取列表第一个元素的更多信息:
getCity().getWeatherList().get(0).getMoreInfo()