Google 天气报告计算出现问题
这是关于 Google 天气报告 XML。
Google 到底在打什么算盘?
当我使用 weather=London,UK 关键字进行谷歌搜索时,它显示的内容类似于此屏幕截图,
替代文本 http://img293.imageshack.us/img293/4746/weathergoogle.jpg
在我的 XML 中,没有像 26、11、26、22 这样的内容,
我的 XML 如下所示。
天气预报中涉及什么计算?
如何将这些放入 PHP 变量中?
This is about the Google Weather Report XML.
What is the calculation Google is doing?
When I google with weather=London,UK keyword, it's showing something like this screen shot,
alt text http://img293.imageshack.us/img293/4746/weathergoogle.jpg
In my XML there is nothing like 26, 11, 26, 22 no
My XML look like below.
What is the calculation involved in the weather report?
How to get these into PHP variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有计算。您链接的 XML 具有以下节点:
前
两个是当前天气的摄氏温度和华氏温度,对应于 Google Seach 页面的左侧部分。高低是 Google 搜索页面显示的预测内容(仅限摄氏度)。
PHP 提供了许多用于处理 XML 的库。最突出的是 DOM、XMLReader 和 SimpleXML。查看 PHP 手册中的示例了解如何使用它们。 Stack Overflow 上还有许多有关其使用的问题和解答。
更新后编辑:似乎谷歌会根据请求提要的浏览器中设置的语言为您提供华氏度的高/低值。将语言参数
hl=[languagecode]
添加到 URL,看看您是否可以用摄氏度请求此参数,或者 - 如果不可能 - 手动转换高/低:There is no calculation. The XML you linked has these nodes:
and
The first two are the temperature in Celsius and Fahrenheit for the current weather and corresponds to the left hand part on the Google Seach page. High and Low is what the Google Search Page shows for the Forecast (Celsius only).
PHP provides a number of libraries for working with XML. The most prominent being DOM, XMLReader and SimpleXML. Have a look at the examples in the PHP Manual on how to use them. Stack Overflow also has numerous questions and answers regarding their usage.
EDIT after Update: Seems like Google gives you the high/low values in Fahrenheit depending on the language set in the browser requesting the feed. Either add the language param
hl=[languagecode]
to the URL to see if you can request this in Celsius or - if that's not possible - convert high/low by hand:实际上,只需在 URL 末尾添加 &hl=en-GB 即可
http://www.google.com/ig/api ?weather=伦敦,英国&hl=en-GB
应该有效。
对于其他语言,存在解析问题(与 UTF-8 相关),但对于英语要转为摄氏度,您只需切换到 GB 区域设置(默认设置为 US)。
Actually, it's as easy as adding &hl=en-GB to the end of URL
http://www.google.com/ig/api?weather=London,UK&hl=en-GB
should work.
For other languages there are parsing problems (UTF-8 related), but for English to turn to Centigrade you just need to switch to GB locale (US is set by default).
这段代码解决了我的问题,带有图像的 Google 天气 API,PHP。
This snippet fixed my problem, Google weather API with image, PHP.
正如 AR 所解释的,返回摄氏度值实际上就像传递语言代码一样简单。
Google 天气 API 没有正式记录,但我发现这两个链接很有用:
As AR explains, returning Celsius values really is as easy as passing the language code.
The Google weather API isn't officially documented, but I found these 2 links useful: