Exemple #1
0
        public virtual async Task <OpenWeatherRoot> GetForecastsAsync(double latitude, double longitude)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://api.openweathermap.org");
                var response = await client.GetAsync($"/data/2.5/forecast?lat={latitude}&lon={longitude}&appid={_config?.Value?.OpenWeatherMap_API_Key}&units=metric");

                response.EnsureSuccessStatusCode();

                var json = await response.Content.ReadAsStringAsync();

                dynamic d = JsonConvert.DeserializeObject(json);

                OpenWeatherRoot deserialized = JsonConvert.DeserializeObject <OpenWeatherRoot>(json);
                return(deserialized);
            }
        }
        private async void currentWeatheButton_Clicked(object sender, EventArgs e)
        {
            var             weather        = new WeatherAPI();
            var             city           = enteredCity.Text;
            OpenWeatherRoot currentWeather = await weather.GetCurrentWeather(city);

            if (currentWeather != null)
            {
                // Gets the correponding image source
                string imageSource = weather.GetWeatherImage(currentWeather);
                weatherImage.Source = imageSource;


                // Changes the text on the corresponding fields
                currentTempLabel.Text = currentWeather.Main.Temp.ToString();
                minTempLabel.Text     = currentWeather.Main.Temp_min.ToString();
                maxTempLabel.Text     = currentWeather.Main.Temp_max.ToString();
                currentHumLabel.Text  = currentWeather.Main.Humidity.ToString();
            }
        }
        public static OpenWeatherRoot GetOpenWeatherRootData()
        {
            var root = new OpenWeatherRoot()
            {
                cod  = "200",
                list = new List <List>()
                {
                },
            };

            root.list.Add(new List()
            {
                main = new Main()
                {
                },
                weather = new List <Weather>()
                {
                },
            });


            return(root);
        }