Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WeatherClass {
- static double temp;
- private static String OPEN_WEATHER_MAP_API = "97e202a04a512514be6c36668fb2a5e3";
- public static double setWeatherCity(final double latitude, double longitude, final Context context){
- new WeatherManager("97e202a04a512514be6c36668fb2a5e3").getFiveDayForecastByCoordinates(latitude,longitude,
- new WeatherManager.ForecastHandler() {
- @Override
- public void onReceivedForecast(WeatherManager manager, Forecast forecast) {
- // Handle forecast
- List<Double> list = new ArrayList<>();
- for (int i = 0; i < 5; i++) {
- long timestamp = forecast.getTimestampByIndex(i+3);
- Weather weatherForTimestamp = forecast.getWeatherForTimestamp(timestamp);
- Temperature tempMini = weatherForTimestamp.getTemperature().getMinimum();
- double temperatureInCelcius = tempMini.getValue(TemperatureUnit.CELCIUS);
- list.add(temperatureInCelcius);
- Log.v("Weather", "" +weatherForTimestamp.getWind().getSpeed());
- Log.v("Weather", "Température mini : " + " "+ list.get(i));
- }
- int minIndex = list.indexOf(Collections.min(list));
- Log.v("Weather MINI", "Température mini : " + list.get(minIndex));
- //Toast.makeText(context, "Température mini: " + list.get(minIndex), Toast.LENGTH_LONG).show();
- temp = list.get(minIndex);
- Log.v("WeatherClass", temp + "");
- /*for (int timestampIndex = 0; timestampIndex < numberOfAvailableTimestamps; timestampIndex++) {
- long timestamp = forecast.getTimestampByIndex(timestampIndex);
- Weather weatherForTimestamp = forecast.getWeatherForTimestamp(timestamp);
- Temperature tempMin = weatherForTimestamp.getTemperature().getMinimum();
- double temperatureInCelcius = tempMin.getValue(TemperatureUnit.CELCIUS); // 0.0 degrees
- }*/
- }
- @Override
- public void onFailedToReceiveForecast(WeatherManager manager) {
- Log.v("TAG", " ERREUR");
- temp = -1000000;
- }
- }
- );
- return temp;
- }
- }
- temp = WeatherClass.setWeatherCity(latitude, longitude, getApplicationContext());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement