• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Java
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A wrapper for the openweathermap REST API

OpenWeatherMap-Android-Library

You need an API Key to use the OpenWeatherMap API. Head on over to their website if you don't already have one.

Download

Step 1. Add the JitPack repository to your root build.gradle file.

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2 : Download via Gradle:

implementation 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:2.1.0'

Note: Remember to include the INTERNET permission to your manifest file

Usage

Instantiate Class With Your OpenWeatherMap Api Key

OpenWeatherMapHelper helper = new OpenWeatherMapHelper(getString(R.string.OPEN_WEATHER_MAP_API_KEY));

Set your Units (Optional, STANDARD by default)

helper.setUnits(Units.IMPERIAL);
Unit Options:
  1. Units.IMPERIAL (Fahrenheit)

  2. Units.METRIC (Celsius)

Set your Language (ENGLISH by default)

helper.setLanguage(Languages.ENGLISH);

Features

(1) Current Weather

Get current weather by City Name:

 helper.getCurrentWeatherByCityName("Accra", new CurrentWeatherCallback() {
     @Override
     public void onSuccess(CurrentWeather currentWeather) {
         Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
                         +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n"
                         +"Temperature: " + currentWeather.getMain().getTempMax()+"\n"
                         +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
                         +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Get current weather by City ID:

 helper.getCurrentWeatherByCityID("524901", new CurrentWeatherCallback() {
     @Override
     public void onSuccess(CurrentWeather currentWeather) {
         Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
                         +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n"
                         +"Temperature: " + currentWeather.getMain().getTempMax()+"\n"
                         +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
                         +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Get current weather by Geographic Coordinates:

 helper.getCurrentWeatherByGeoCoordinates(5.6037, 0.1870, new CurrentWeatherCallback() {
     @Override
     public void onSuccess(CurrentWeather currentWeather) {
         Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
                         +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n"
                         +"Temperature: " + currentWeather.getMain().getTempMax()+"\n"
                         +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
                         +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Get current weather by Zip Code:

 helper.getCurrentWeatherByZipCode("90003", new CurrentWeatherCallback() {
     @Override
     public void onSuccess(CurrentWeather currentWeather) {
         Log.v(TAG, "Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLon() +"\n"
                         +"Weather Description: " + currentWeather.getWeather().get(0).getDescription() + "\n"
                         +"Temperature: " + currentWeather.getMain().getTempMax()+"\n"
                         +"Wind Speed: " + currentWeather.getWind().getSpeed() + "\n"
                         +"City, Country: " + currentWeather.getName() + ", " + currentWeather.getSys().getCountry()
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

(2) 5 day / 3 hour forecast

Get three hour forecast by City Name:

 helper.getThreeHourForecastByCityName("Pretoria", new ThreeHourForecastCallback() {
     @Override
     public void onSuccess(ThreeHourForecast threeHourForecast) {
         Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
                         +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
                         //For this example, we are logging details of only the first forecast object in the forecasts array
                         +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n"
                         +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n"
                         +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n"
                         +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n"
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Get three hour forecast by City ID:

 helper.getThreeHourForecastByCityID("524901", new ThreeHourForecastCallback() {
     @Override
     public void onSuccess(ThreeHourForecast threeHourForecast) {
         Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
                         +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
                         //For this example, we are logging details of only the first forecast object in the forecasts array
                         +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n"
                         +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n"
                         +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n"
                         +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n"
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Get three hour forecast by Geographic Coordinates:

 helper.getThreeHourForecastByGeoCoordinates(6.5244,3.3792, new ThreeHourForecastCallback() {
     @Override
     public void onSuccess(ThreeHourForecast threeHourForecast) {
         Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
                         +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
                         //For this example, we are logging details of only the first forecast object in the forecasts array
                         +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n"
                         +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n"
                         +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n"
                         +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n"
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Get three hour forecast by Zip Code:

 helper.getThreeHourForecastByZipCode("94040", new ThreeHourForecastCallback() {
     @Override
     public void onSuccess(ThreeHourForecast threeHourForecast) {
         Log.v(TAG, "City/Country: "+ threeHourForecast.getCity().getName() + "/" + threeHourForecast.getCity().getCountry() +"\n"
                         +"Forecast Array Count: " + threeHourForecast.getCnt() +"\n"
                         //For this example, we are logging details of only the first forecast object in the forecasts array
                         +"First Forecast Date Timestamp: " + threeHourForecast.getList().get(0).getDt() +"\n"
                         +"First Forecast Weather Description: " + threeHourForecast.getList().get(0).getWeather().get(0).getDescription()+ "\n"
                         +"First Forecast Max Temperature: " + threeHourForecast.getList().get(0).getMain().getTempMax()+"\n"
                         +"First Forecast Wind Speed: " + threeHourForecast.getList().get(0).getWind().getSpeed() + "\n"
         );
     }

     @Override
     public void onFailure(Throwable throwable) {
         Log.v(TAG, throwable.getMessage());
     }
 });

Upcoming Features

  1. Hourly Forecast 4 days
  2. Daily Forecast 16 days

More Repositories

1

News-API-Java

An wrapper for newsapi.org
Java
26
star
2

Currency-Converter

An Offline-First Currency Converter For Android and iOS Built With Kotlin Multiplatform 
Kotlin
14
star
3

Spotify-2021-Compose-Multiplatform

A 2021 Spotify UI Built With Compose Multiplatform
Kotlin
13
star
4

Finito

A simple note taking app based on the MVVM Architecture using Test-Driven Development, Kotlin, Android Architecture Components, Data Binding, Coroutines, Dagger 2 etc.
Kotlin
12
star
5

expressjs-force-https

A simple express.js middleware that redirects incoming unencrypted HTTP requests to HTTPS.
JavaScript
11
star
6

OpenWeatherMap-Node

An Openweathermap wrapper for nodejs
JavaScript
10
star
7

nestjs-testing

Learning unit and end to end testing in nestjs
TypeScript
10
star
8

CoinTrack-Android-MVVM

Mastering android architecture components by building a real-time cryptocurrency coin tracking app
Java
9
star
9

hubtel-sms

A Node.js wrapper for Hubtel's Sms API.
TypeScript
9
star
10

SmsRetreiver-Sample

A Tutorial on Automatic SMS Verification using Android's SMS Retrieval API
Kotlin
8
star
11

SmsBroadcastReceiver

‼️ **DEPRECATED** An Android Broadcast Receiver Library For Capturing/Reading Incoming SMS.
Java
6
star
12

Movies

Learning Flutter's Declarative UI And Flutter Bloc By Building A Simple Movies App
Dart
4
star
13

Buddy

My entry for week 1 of the AndroidDevChallenge
Kotlin
3
star
14

epaygh

A Node.js wrapper for Epay's API.
TypeScript
3
star
15

nestjs-objection-sample

A sample app demonstrating the use of the Nestjs-Objection library.
TypeScript
3
star
16

Spotify-2021-SwiftUI

A 2021 Spotify UI Built With SwiftUI
Swift
3
star
17

ajax-request

HTML
2
star
18

mailtrap-tutorial

A Tutorial on Email Testing using Mailtrap.io
JavaScript
2
star
19

Sms-Retrieval-API-Android

A sample project demonstrating automatic sms retrieval with the use of Google's SMS Retrieval API for automatic SMS verification
Java
2
star
20

RecompositionDemo

Kotlin
1
star
21

node-backend-starter

A personal starter project for my node based projects.
TypeScript
1
star
22

file-upload-server

A simple node server for testing multipart/form-data uploads from clients
JavaScript
1
star
23

RickAndMorty

Practicing Kotlin Coroutines and Flow
Kotlin
1
star
24

SwiftfulCrypto

This is an iOS crypto tracking app created using SwiftUI and Clean Architecture
Swift
1
star