文件名称:C# 获取即时天气状况
文件大小:16KB
文件格式:CS
更新时间:2016-04-06 08:15:51
C# 天气状况
根据经纬度获取当地的即时天气状况 public weather(string latitude, string longtitude) //经伟度 { try { string output = "json"; string url = string.Format("http://maps.google.cn/maps/geo?output={0}&key=abcdef&q={1},{2}", output, latitude, longtitude); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string[] tmpArray = sr.ReadToEnd().Split(','); string sProvince = getString(tmpArray, "\"AdministrativeAreaName", 1); string sCity1 = getString(tmpArray, "\"LocalityName", 2); string sCity2 = getString(tmpArray, "\"DependentLocalityName", 3); string sWeatherCode = getWeatherCode(sProvince, sCity1, sCity2); //取省市区三级城市代码 getWeather(sWeatherCode, 3); } } catch { } }