Example #1
0
        async public void Show(string cityName)
        {
            string Address = "http://api.map.baidu.com/telematics/v3/weather?location=" + cityName + "&output=json&ak=Gi27P5bmIinr86htrjU4ESnY";


            try
            {
                //var strinfo = await httpClient.GetStringAsync(Address);
                var strinfo = await httpClient.GetStringAsync(Address);

                //json解析
                weatherData = JsonAnalytical(strinfo);
                //xml解析
                //weatherData = XmlAnalytical(strinfo);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("网络请求失败!" + ex.Message.ToString());
            }


            listIndex.Visibility    = Windows.UI.Xaml.Visibility.Collapsed;
            listWeather.Visibility  = Windows.UI.Xaml.Visibility.Visible;
            listWeather.ItemsSource = weatherData.results[0].weather_data;
            //listIndex.ItemsSource = weatherData.results[0].index;
            textPmName.Text     = "PM2.5";
            dayPicture.Source   = (new BitmapImage(new Uri(weatherData.results[0].weather_data[0].dayPictureUrl.ToString())));
            nightPicture.Source = (new BitmapImage(new Uri(weatherData.results[0].weather_data[0].nightPictureUrl.ToString())));
            date.Text           = weatherData.results[0].weather_data[0].date;
            weather.Text        = weatherData.results[0].weather_data[0].weather;
            wind.Text           = weatherData.results[0].weather_data[0].wind;
            temperature.Text    = weatherData.results[0].weather_data[0].temperature;
            textCity.Text       = weatherData.results[0].currentCity;
            textPm.Text         = weatherData.results[0].pm25;
            showCity.Text       = cityName;



            bt       = new Btn();
            bt.zero  = "天气情况";
            bt.one   = "穿衣指数";
            bt.two   = "洗车指数";
            bt.three = "旅游指数";
            bt.four  = "感冒指数";
            bt.five  = "运动指数";
            bt.six   = "紫外线强度指数";

            btn.Add(bt);

            listbtn.ItemsSource = btn;
        }
Example #2
0
         async public void Show(string  cityName)
        {

            string Address = "http://api.map.baidu.com/telematics/v3/weather?location=" + cityName + "&output=json&ak=Gi27P5bmIinr86htrjU4ESnY";


            try
            {

                //var strinfo = await httpClient.GetStringAsync(Address);
                var strinfo = await httpClient.GetStringAsync(Address);
                //json解析
                weatherData = JsonAnalytical(strinfo);
                //xml解析
                //weatherData = XmlAnalytical(strinfo);
              
            }
            catch (Exception ex)
            {
                Debug.WriteLine("网络请求失败!" + ex.Message.ToString());

            }

        
            listIndex.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            listWeather.Visibility = Windows.UI.Xaml.Visibility.Visible;
            listWeather.ItemsSource = weatherData.results[0].weather_data;
            //listIndex.ItemsSource = weatherData.results[0].index;
            textPmName.Text = "PM2.5";
            dayPicture.Source = (new BitmapImage(new Uri(weatherData.results[0].weather_data[0].dayPictureUrl.ToString())));
            nightPicture.Source = (new BitmapImage(new Uri(weatherData.results[0].weather_data[0].nightPictureUrl.ToString())));
            date.Text = weatherData.results[0].weather_data[0].date;
            weather.Text = weatherData.results[0].weather_data[0].weather;
            wind.Text = weatherData.results[0].weather_data[0].wind;
            temperature.Text = weatherData.results[0].weather_data[0].temperature;
            textCity.Text = weatherData.results[0].currentCity;
            textPm.Text = weatherData.results[0].pm25;     
            showCity.Text = cityName;
             


            bt = new Btn();
            bt.zero = "天气情况";
            bt.one = "穿衣指数";
            bt.two = "洗车指数";
            bt.three = "旅游指数";
            bt.four = "感冒指数";
            bt.five = "运动指数";
            bt.six = "紫外线强度指数";

            btn.Add(bt);

            listbtn.ItemsSource = btn;
           
           
          

        }