You need an API Key to use the OpenWeatherMap API. Head on over to their website if you don't already have one.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
compile 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:v1.0.0'
Note: Remember to include the INTERNET permission to your manifest file
OpenWeatherMapHelper helper = new OpenWeatherMapHelper();
helper.setApiKey(getString(R.string.OPEN_WEATHER_MAP_API_KEY));
helper.setUnits("imperial");
-
"imperial"
-
"fahrenheit"
helper.getCurrentWeatherByCityName("Accra", new OpenWeatherMapHelper.CurrentWeatherCallback() {
@Override
public void onSuccess(CurrentWeather currentWeather) {
Log.v(TAG,
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLat() +"\n"
+"Weather Description: " + currentWeather.getWeatherArray().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());
}
});
helper.getCurrentWeatherByCityID("524901", new OpenWeatherMapHelper.CurrentWeatherCallback() {
@Override
public void onSuccess(CurrentWeather currentWeather) {
Log.v(TAG,
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLat() +"\n"
+"Weather Description: " + currentWeather.getWeatherArray().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());
}
});
helper.getCurrentWeatherByGeoCoordinates(5.6037, 0.1870, new OpenWeatherMapHelper.CurrentWeatherCallback() {
@Override
public void onSuccess(CurrentWeather currentWeather) {
Log.v(TAG,
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLat() +"\n"
+"Weather Description: " + currentWeather.getWeatherArray().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());
}
});
helper.getCurrentWeatherByZipCode("90003", new OpenWeatherMapHelper.CurrentWeatherCallback() {
@Override
public void onSuccess(CurrentWeather currentWeather) {
Log.v(TAG,
"Coordinates: " + currentWeather.getCoord().getLat() + ", "+currentWeather.getCoord().getLat() +"\n"
+"Weather Description: " + currentWeather.getWeatherArray().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());
}
});
- 5 day / 3 hour forecast
- 16 day / daily forecast