public async Task <Framework.Weather.WeatherDTO> GetForecastToday(double latitude, double longtitude, string cityName) { if (this._WeatherProvider == null) { throw new NotImplementedException(); } var retval = new Framework.Weather.WeatherDTO(); _WeatherProvider.Longtitude = longtitude; _WeatherProvider.Latitude = latitude; //_WeatherProvider.CityName = cityName; retval = await _WeatherProvider.GetWeather(); retval.Status = true; if (retval != null) { //retval.WeatherDetails.Location += " weather"; if (retval.WeatherDetails.WeatherCondition.Contains("cloud")) { retval.Message = "Beautiful sunsets need cloudy skies..."; } else if (retval.WeatherDetails.WeatherCondition.Contains("rain")) { retval.Message = "Bring a raincoat. It's gonna get wet!"; } else if (retval.WeatherDetails.WeatherCondition.Contains("snow")) { retval.Message = "Brace yourself, winter is coming!"; } else if (retval.WeatherDetails.WeatherCondition.Contains("clear")) { retval.Message = "Beautiful clear sky"; } else if (retval.WeatherDetails.WeatherCondition == "error") { retval.Message = "Unable to fetch weather forecast in your location"; retval.Status = false; } } return(retval); }
public async Task <Framework.Weather.WeatherDTO> GetWeather() { var retval = new Framework.Weather.WeatherDTO(); //Sign up for a free API key at http://openweathermap.org/appid string key = "dd93bb1183fe52148d430f3e2c7415e3"; string queryString = $"https://api.openweathermap.org/data/2.5/weather?lat={this.Latitude}&lon={this.Longtitude}&appid={key}"; // &units=metric (but by default, it's set in Kelvin); if (this.Longtitude <= 180) { queryString = $"https://api.openweathermap.org/data/2.5/weather?lat={this.Latitude}&lon={this.Longtitude}&appid={key}"; } else { queryString = $"https://api.openweathermap.org/data/2.5/weather?q={this.CityName}&appid={key}"; } var result = await Framework.Weather.LiteWebClient.Request <Framework.Weather.OpenWeatherMap.OpenWeatherMapDTO>(queryString); if (result != null && result.cod == 200) { retval.WeatherDetails.Location = result.name; retval.WeatherDetails.Temperature = result.main.temp; retval.WeatherDetails.TemperatureC = ToCelcius(result.main.temp, result); // default unit is set to Kelvin retval.WeatherDetails.TemperatureF = ToFahrenheit(result.main.temp, result); // default unit is set to Kelvin retval.WeatherDetails.WeatherIcon = $"http://openweathermap.org/img/w/{result.weather[0].icon}.png"; retval.WeatherDetails.TemperatureMax = ToCelcius(result.main.temp_max, result); retval.WeatherDetails.TemperatureMin = ToCelcius(result.main.temp_min, result); retval.WeatherDetails.Humidity = result.main.humidity; retval.WeatherDetails.WeatherCondition = result.weather[0].main.ToLower(); } else { retval.WeatherDetails.WeatherCondition = "error"; } return(retval); }