ronrihoo / Java-OpenWeatherMap-API

A light Java API for OpenWeatherMap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java OpenWeatherMap API

Release

A light OpenWeatherMap API for Java.

Setup

  1. Either build the JAR or download it from the latest release

  2. Create a folder, "lib", in the directory of a new/existing project

  3. Move or copy the JAR file into the lib folder

  4. Add the JAR file to the build path

    IDEA: From the Project window, select and right-click the lib folder, then click Add as Library...

    Eclipse: From the Package Explorer, select and right-click the JAR file, then select Build and click Add to Build Path

Usage

  1. In a Java source file, import the OpenWeatherMap API
import owmapi.OwmApi;
  1. Create an instance of the API
OwmApi owmApi = new OwmApi();
  1. Set the OpenWeatherMap App ID by passing it as a string
owmApi.setAppId("OWM-App-ID-Here");
  1. Get weather report based on zipcode
String weatherReport = owmApi.runWithZipcode("75080-3021");

A Complete Example

import owmapi.OwmApi;

public class Main {

    public static void main(String[] args) {
        run("OWM-App-ID-Here", "75080-3021");
    }

    public static void run(String appId, String zipcode) {
        OwmApi owmApi = new OwmApi();
        owmApi.setAppId(appId);
        String weatherReport = owmApi.runWithZipcode(zipcode);
        if (weatherReport != null) {
            System.out.println(weatherReport);
        }
    }

}

Result:

Weather forecast for Richardson city: cloudy and a temperature of 80.9 with a high of 84.2 and a low of 77.0

API Reference

setAppId(String)

    Sets the OpenWeatherMap App ID for retrieving data from the web API

runWithZip(String)

    Runs the Java OpenWeatherMap API using zip code information

Note: This API includes more methods; however, this covers the majority of its functionality at this time.

Contributing

All pull requests are welcome.

About

A light Java API for OpenWeatherMap


Languages

Language:Java 100.0%