谁有 js,jq,等等方法 动态获取 天气预报?只要对我有帮助的

JavaScript014

谁有 js,jq,等等方法 动态获取 天气预报?只要对我有帮助的,第1张

//这是我以前开发天气wedget的时候写过的代码,原理是连接到yahoo api(返回XML),先用cityCode查国家 然后用woeid查地方,这是测试时写过的代码。Yahoo 天气api 好像一部分收费 最后没用yahoo 用 weatherbug的api 那个代码忘了存在哪里了,如果 非常着急的话在跟我说吧 我给你找找,还有调用api的原理,一般不会直接调用api 因为每个人访问时都调用一次的话系统受不了。最好写个windows service 每个一段时间调用一次api然后以.xml形式存放到一个文件夹,在系统中只调用xml文件就好了。如果api一时访问不到了也不会出问题。

才看到你想要的是前台代码, 这是后台的

private string GetWeather(string cityCode)

{

string weather = string.Empty

if (cityCode == "" || string.IsNullOrEmpty(cityCode)) { cityCode = "seoul"}

XmlDocument document1 = new XmlDocument()

document1.Load("http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text=" + cityCode + "&format=xml")

XmlNodeList nodes1 = document1.GetElementsByTagName("woeid")

string strWoeid = nodes1[0].InnerText

XmlDocument document = new XmlDocument()

document.Load("http://weather.yahooapis.com/forecastrss?w=" + strWoeid + "&u=c")

XmlNodeList nodes = document.GetElementsByTagName("forecast",

@"http://xml.weather.yahoo.com/ns/rss/1.0")

foreach (XmlNode node in nodes)

{

Console.WriteLine("日期:{0},星期:{1},天气:{2},温度:{3}°C 至 {4}°C",

node.Attributes["date"].InnerText,

node.Attributes["day"].InnerText,

node.Attributes["text"].InnerText,

node.Attributes["low"].InnerText,

node.Attributes["high"].InnerText)

//FToC(int.Parse(node.Attributes["low"].InnerText)),

// FToC(int.Parse(node.Attributes["high"].InnerText)))

// //woeid

// // http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text="Wonju"&format=xml

}

return weather

}

1、首先我们新建名为Default的测试页面。

2、在页面中加入用于显示测试结果的标签。

3、然后我们根据图示代码判断Chrome浏览器。

4、然后我们根据图示代码判断Firefox浏览器。

5、然后我们根据图示代码判断IE的Edge浏览器。

6、然后我们根据图示代码判断IE的非Edge浏览器即可。

在高中学过的知识中,可以很肯定的告诉你是——风玫瑰图(但不确定它具体属于哪一种)。

风玫瑰图:指某地区一定时间内的各种风向、风速和根据风向风速对大气污染综合影响的资料绘制在方位图上的图形。

分类:风玫瑰图包括风向玫瑰图(风向频率图)、风速玫瑰图和污染系数(风向风速综合影响)玫瑰图。

应用:城市规划、气象信息服务系统等。

希望能帮到你哦!