在Lat和Lon上使用Google Weather API-如何格式化? [英] Using Google Weather API with Lat and Lon - how to format?

查看:112
本文介绍了在Lat和Lon上使用Google Weather API-如何格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google Weather API-通过传递lat和long值.我正在存储这些值,但是Google似乎需要以不同的格式显示这些值.

I want to use the Google Weather API - by passing lat and long values. I am storing these values, however it seems Google needs these values in different format.

即对于McTavish镇,我的值为45.5和-73.583

i.e. For the town of McTavish I have values of 45.5 and -73.583

这在这里有效: http: //api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=45.5,-73.583

但是当我将这些数据用于Google API时,它将无法正常工作:请参阅:www.google.com/ig/api?weather=,,,45.5,-73.583

But when I use these data for Google API, it does not work: See: www.google.com/ig/api?weather=,,,45.5,-73.583

任何帮助表示赞赏.我希望使用Google数据.

Any help appreciated. I would prefer to use the Google Data.

推荐答案

更新后的答案: 我刚刚注意到Google的Weather API还有其他一些违规之处.在任何情况下,如果适用,除负号外,您还需要有8位数字.请参阅以下代码块(基于Java)以获取正确的格式. (不是完美的算法,只是一个简单的示例,以便您可以看到结果)

UPDATED ANSWER: I have just noticed some OTHER irregularities with Google's Weather API. In ANY case, you need to have 8 numerical digits, in addition to the negative sign, if it applies. See the following code block (Java-based) for proper formatting. (Not the perfect algorithm, but just a quick example so that you can see the results)

lat = lat.replace(".", "");
while(lat.length() < 9)
    lat = lat.concat("0");
if(lat.contains("-"))
    lat = lat.substring(0, 9);
else
    lat = lat.substring(0, 8);

原始回应: 保罗,关于Google Weather API的窍门是,您不使用传统纬度/经度收到的坐标.相反,您解析出小数点.此外,Google Weather API的趣味性"似乎是要求数据以7到8位数字的字符串形式出现.因此,例如,45. 5应该确实是45.50000,而-73.583应该真的是-73.58300.这个7到8位数的长度似乎没有在任何负坐标前面包含负号(-).

ORIGINAL RESPONSE: Paul, the trick about Google's Weather API is that you don't use the coordinates as received by traditional latitude/longitude. Instead, you parse out the decimal points. Additionally, a "fun quirk" of Google's Weather API seems to be a requirement that the data come in as a 7- to 8-digit string. So, for instance, 45.5 should really be 45.50000, and -73.583 should really be -73.58300. This length of 7-8 digits does NOT seem to include the negative sign (-) in front of any negative coordinates.

因此,您的45.5(0000)变为4550000,而您的-73.583(00)变为-7358300.因此,最终的网址将是:

So, your 45.5(0000) becomes 4550000, and your -73.583(00) becomes -7358300. So the final URL would be:

http://www.google.com/ig/api?weather=,,,4550000,-7358300

请注意,再次使用7-8位数字表示455000045500000是可以接受的,-7358300-73583000也是可以接受的.

Note that again, 7-8 digits means 4550000 or 45500000 would be acceptable, as would -7358300 or -73583000.

当我看到您的问题时,我才发现大约7到8位数字的长度-我试图将数据输入到我的天气分析程序中,并发现455,-73583无法产生正确的数据.

I only found out about the 7-8 digit length when I saw your question--I tried entering the data into my weather parsing program, and found that 455,-73583 does not yield proper data.

请注意,这是我的非正式实验,而不是官方文档,因此可能还会发现其他怪癖.

Note that this is by my unofficial experimentation, and not by official documentation, so there may be other quirks to be discovered.

这篇关于在Lat和Lon上使用Google Weather API-如何格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆