Easy and quick weather fetching from OpenWeatherMap API for Android.
Add the JitPack repository to your build file, add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies
of your build.gradle
:dependencies {
compile 'com.github.code-crusher:EasyWeather:v1.2'
}
First you would need API_KEY
from OpenWeatherMap and place it in your build.gradle
buildTypes.each {
it.buildConfigField 'String', 'OWM_API_KEY', "\"API_KEY\""
}
First create WeatherMap
object:
WeatherMap weatherMap = new WeatherMap(this, OWM_API_KEY);
To get Current Weather use this in Activity
:
By City Name:
weatherMap.getCityWeather(city, new WeatherCallback() {
@Override
public void success(WeatherResponseModel response) {
Weather weather[] = response.getWeather();
String weatherMain = weather[0].getMain();
}
To get temperature in specific units you can use:
Double temperature = TempUnitConverter.convertToCelsius(response.getMain().getTemp());
To get other details you can use:
String location = response.getName();
String humidity= response.getMain().getHumidity();
String pressure = response.getMain().getPressure();
String windSpeed = response.getWind().getSpeed();
String iconLink = weather[0].getIconLink();
By Location Coordinates:
weatherMap.getLocationWeather(latitude, longitude, new WeatherCallback() {
@Override
public void success(WeatherResponseModel response) {
}
@Override
public void failure(String message) {
}
});
To get Forecast use this in Activity
also you need specify index
to get the specific hour of 3 hour Forecast:
By City Name:
weatherMap.getCityForecast(city, new ForecastCallback() {
@Override
public void success(ForecastResponseModel response) {
Weather weather[] = response.getList()[index].getWeather();
}
@Override
public void failure(String message) {
}
});
By Location Coordinates:
weatherMap.getLocationForecast(latitude, longitude, new ForecastCallback() {
@Override
public void success(ForecastResponseModel response) {
}
@Override
public void failure(String message) {
}
});
Variable | Type |
---|---|
city | String |
index | int |
latitude | String |
longitude | String |
Feel free to submit issues and enhancement requests.
I would love to welcome contributions and support from other developers. Please refer to each project's style guidelines and guidelines for submitting patches and additions. In general, i follow the "fork-and-pull" Git workflow.
Copyright 2016 Vatsal Bajpai
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.