Example for daily weather forecast

Issue #9 resolved
Former user created an issue

Hi!

Are there any possibilities to show any examples for daily weather forecast (for 5 days)? I'm green in Java (also in OWM JAPIs) and really need some examples or tips how can I get temp. , an icon representing the weather and name of the day of week.

I've tried to write code that will works:

public void showForecastWeather() throws APIException {

    DailyWeatherForecast fwd = owm.dailyWeatherForecastByCityName(city);
    System.out.println("City: " + fwd.getCityData());
    System.out.println("Temperature: " + fwd.getCityData().component1());
}

Comments (3)

  1. Ashutosh Kumar Singh repo owner

    Hi, here's an example for getting the hourly forecast using OWM JAPIs. I am providing this example as the daily forecast is not free and may not work for everyone. If you need the daily forecast, replace HourlyWeatherForecast with DailyWeatherForecast.

    import net.aksingh.owmjapis.api.APIException;
    import net.aksingh.owmjapis.core.OWM;
    import net.aksingh.owmjapis.model.HourlyWeatherForecast;
    import net.aksingh.owmjapis.model.param.WeatherData;
    
    class MainFour {
    
      public static void main(String args[]) throws APIException {
        OWM owm = new OWM("YOUR-API-KEY-HERE");
        HourlyWeatherForecast hwd = owm.hourlyWeatherForecastByCityName("London");
    
        System.out.println("City: " + hwd.getCityData().getName());
    
        for (WeatherData data: hwd.getDataList()) {
          System.out.println("Data datetime: " + data.getDateTime());
        }
      }
    }
    

    Hope you found this piece of code helpful. Thanks!

  2. Log in to comment