コード例 #1
0
        internal async void GetWeatherForLocation()
        {
            HttpClient client = new HttpClient();
            var        uri    = new Uri(
                string.Format(
                    $"https://jsonplaceholder.typicode.com/posts/{LocationEnteredByUser}"));
            var response = await client.GetAsync(uri);

            WeatherItem weatherData = null;

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                weatherData = WeatherItem.FromJson(content);
            }
            WeatherCollection.Add(weatherData);
        }
コード例 #2
0
        internal async void GetWeatherForLocation()
        {
            HttpClient client = new HttpClient();
            var        uri    = new Uri(
                string.Format(
                    $"http://api.openweathermap.org/data/2.5/weather?q={LocationEnteredByUser}&units=imperial&APPID=" +
                    $"{ApiKey.WeatherAPIKey}"));
            var response = await client.GetAsync(uri);

            WeatherItem weatherData = null;

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                weatherData = WeatherItem.FromJson(content);
            }
            WeatherCollection.Add(weatherData);
        }
コード例 #3
0
        internal async void GetWeatherForLocation()
        {
            //need Microsoft.Net.Http to use HTTP (and maybe Microsoft.BCL.Build if you're having issues like me)

            HttpClient client = new HttpClient(); //makes new accesable HTTP client

            var uri = new Uri(                    //gets the URI from openweather
                string.Format(
                    $"http://api.openweathermap.org/data/2.5/weather?q={LocationEnteredByUser}&units=imperial&APPID=" + $"5da8d96113a5c72f1f9836c3c84a6351"));
            var response = await client.GetAsync(uri);

            WeatherItem weatherData = null;

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                weatherData = WeatherItem.FromJson(content);
            }
            WeatherCollection.Add(weatherData);
        }
コード例 #4
0
        internal async void GetWeatherForLocation()
        {
            Analytics.TrackEvent("GetWeatherButtonTapped", new Dictionary <string, string> {
                { "WeatherLocation", LocationEnteredByUser },
            });

            HttpClient client = new HttpClient();
            var        uri    = new Uri(
                string.Format(
                    $"http://api.openweathermap.org/data/2.5/weather?q={LocationEnteredByUser}&units=imperial&APPID=" +
                    $"{ApiKeys.WeatherKey}"));
            var response = await client.GetAsync(uri);

            WeatherItem weatherData = null;

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                weatherData = WeatherItem.FromJson(content);
            }
            WeatherCollection.Add(weatherData);
        }