2

我的应用程序使用 yahoo 的天气提要 (XML) 来显示未来 5 天的天气预报。当邮政编码在美国时,这很好用。例如,下面的 url 为我提供了密歇根州富兰克林的提要。

http://xml.weather.yahoo.com/forecastrss/48025_f.xml

我也需要加拿大的类似提要,但似乎无法正常工作。例如,'Scarborough' 的邮政编码是 M1M1M1。试过了

http://xml.weather.yahoo.com/forecastrss/M1M1M1_f.xml

但这不起作用。

提前致谢

4

1 回答 1

3

我正在可靠地使用:

http://weather.yahooapis.com/forecastrss?w=location

在哪里w = WOEIDScarborough, Canada w=4369为什么:

http://weather.yahooapis.com/forecastrss?w=4369

将正确返回天气数据。有关 API 的更多信息,请点击此处

我也使用这种方法来获取WOEID给定位置名称字符串:

// Create new XML doc
XmlDocument xmldoc = new XmlDocument();
// Get XML doc
xmldoc.Load(string.Format("http://where.yahooapis.com/v1/places.q({0})?appid={1}", place, ApplicationID));
string woeid = xmldoc.GetElementsByTagName("woeid")[0].InnerText;
return woeid;    

但要使其正常工作,您需要通过注册您的应用程序来获取ApplicationIDfrom 。Yahoo

于 2012-08-28T15:23:19.500 回答