{"id":749,"date":"2011-11-09T16:09:41","date_gmt":"2011-11-09T08:09:41","guid":{"rendered":""},"modified":"2014-03-11T22:40:06","modified_gmt":"2014-03-11T14:40:06","slug":"asp%e5%88%a9%e7%94%a8prototype%e5%92%8cgoogle%e7%9a%84weather-api%e5%81%9a%e5%a4%a9%e6%b0%94%e9%a2%84%e6%8a%a5","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2011\/11\/09\/749.htm","title":{"rendered":"ASP\u5229\u7528prototype\u548cGoogle\u7684weather api\u505a\u5929\u6c14\u9884\u62a5"},"content":{"rendered":"<p>\u5229\u7528prototype\u548cGoogle\u7684weather api\u505a\u5929\u6c14\u9884\u62a5<br \/>\n\u60f3\u62ffprototype\u7ec3\u7ec3\u624b\uff0c\u5c31\u7528prototype\u505a\u4e2a\u5929\u6c14\u9884\u62a5\u5427\u3002 <br \/>\nGoogle Weather API \u53ea\u652f\u6301\u7f8e\u56fd\u5730\u533a\u4f7f\u7528\u90ae\u653f\u7f16\u7801\u8fdb\u884c\u67e5\u8be2,\u4f8b\u5982:<br \/>\n<a rel=\"nofollow\" href=\"http:\/\/www.Google.com\/ig\/api?hl=zh-cn&amp;weather=94043\">http:\/\/www.Google.com\/ig\/api?hl=zh-cn&amp;weather=94043<\/a><br \/>\n(94043 \u4e3a \u5c71\u666f\u57ce, \u7f8e\u56fd\u52a0\u5dde \u7684\u90ae\u653f\u7f16\u7801)<br \/>\n\u800c\u9664\u4e86\u7f8e\u56fd\u4ee5\u5916\u7684\u5730\u533a\u9700\u8981\u4f7f\u7528\u7ecf\u7eac\u5ea6\u5750\u6807\u4f5c\u4e3a\u53c2\u6570\u624d\u80fd\u6267\u884c Google Weather API, \u4f8b\u5982:<br \/>\n<a rel=\"nofollow\" href=\"http:\/\/www.Google.com\/ig\/api?hl=zh-cn&amp;weather=,,,30670000,104019996\">http:\/\/www.Google.com\/ig\/api?hl=zh-cn&amp;weather=,,,30670000,104019996<\/a><br \/>\n(30670000,104019996 \u4e3a \u6210\u90fd, \u4e2d\u56fd\u5927\u9646 \u7684\u7ecf\u7eac\u5ea6\u5750\u6807)<br \/>\n\u8981\u5176\u5b83\u5730\u533a\u7684\u7ecf\u7eac\u5ea6\u5750\u6807,\u53ef\u4ee5\u901a\u8fc7 Google API \u63d0\u4f9b\u7684\u56fd\u5bb6\u4ee3\u7801\u5217\u8868\u53ca\u76f8\u5e94\u7684\u57ce\u5e02\u7ecf\u7eac\u5ea6\u5750\u6807\u5217\u8868\u53ef\u4ee5\u67e5\u8be2\u5230,\u4ee5\u4e0b\u662f Google API \u63d0\u4f9b\u7684\u67e5\u8be2\u53c2\u6570:<br \/>\n<a rel=\"nofollow\" href=\"http:\/\/www.Google.com\/ig\/countries?output=xml&amp;hl=zh-cn\">http:\/\/www.Google.com\/ig\/countries?output=xml&amp;hl=zh-cn<\/a><br \/>\nASP\u6f14\u793a:http:\/\/www.knowsky.com\/tools\/tianqiyubao.asp<br \/>\n(\u67e5\u8be2 Google \u6240\u652f\u6301\u7684\u6240\u6709\u56fd\u5bb6\u7684\u4ee3\u7801,\u5e76\u4ee5 zh-cn \u7b80\u4f53\u4e2d\u6587\u663e\u793a)<br \/>\n<a rel=\"nofollow\" href=\"http:\/\/www.Google.com\/ig\/cities?output=xml&amp;hl=zh-cn&amp;country=cn\">http:\/\/www.Google.com\/ig\/cities?output=xml&amp;hl=zh-cn&amp;country=cn<\/a><\/p>\n<p>\uff1a&lt;!DOCTYPE HTML PUBLIC &quot;-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN&quot;&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt; New Document &lt;\/title&gt;<br \/>\n&lt;meta name=&quot;Generator&quot; content=&quot;EditPlus&quot;&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;script language=&quot;javascript&quot; src=&quot;prototype.js&quot;&gt;&lt;\/script&gt;<br \/>\n&lt;script language=&quot;javascript&quot;&gt;<\/p>\n<p>\/\/\u53d6\u5f97\u4e2d\u56fd\u6240\u6709\u7684\u57ce\u5e02<br \/>\nfunction getCity()<br \/>\n{<br \/>\nvar url = &quot;<a rel=\"nofollow\" href=\"http:\/\/www.Google.com\/ig\/cities\">http:\/\/www.Google.com\/ig\/cities<\/a>&quot;;<br \/>\nvar cityPara = {method:&quot;get&quot; , <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; parameters:&quot;output=xml&amp;hl=zh-cn&amp;country=cn&quot; ,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; onComplete:showCityRespose<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; };<br \/>\nvar cityRequest = new Ajax.Request( url , cityPara);<br \/>\n}<\/p>\n<p>function showCityRespose(originalRequest)<br \/>\n{<br \/>\ncityInfo = originalRequest.responseXML;<br \/>\ncityNodes = cityInfo.getElementsByTagName(&quot;city&quot;);<br \/>\nfor(var i=0;i&lt;cityNodes.length;i++){<br \/>\n&nbsp; var city = cityNodes[i];<br \/>\n&nbsp; var cityName = getData( city , &quot;name&quot;);<br \/>\n&nbsp; var latitude = getData( city ,&quot;latitude_e6&quot;);<br \/>\n&nbsp; var longitude= getData( city ,&quot;longitude_e6&quot;);<br \/>\n&nbsp; var option =document.createElement(&quot;option&quot;);<br \/>\n&nbsp; $(&quot;city&quot;).options.add(option);<br \/>\n&nbsp; option.innerText = cityName;<br \/>\n&nbsp; option.value=&quot;,,,&quot;+latitude+&quot;,&quot;+longitude;<br \/>\n}<br \/>\n}<br \/>\nfunction forecast(city)<br \/>\n{<br \/>\n$(&quot;result&quot;).innerHTML = &quot;\u8bf7\u7a0d\u7b49&quot;;<br \/>\nvar url = &quot;<a rel=\"nofollow\" href=\"http:\/\/www.Google.com\/ig\/api\">http:\/\/www.Google.com\/ig\/api<\/a>&quot;;<br \/>\nvar para = {method:&quot;get&quot; , <br \/>\n&nbsp; parameters:&quot;hl=zh-cn&amp;weather=&quot;+city ,<br \/>\n&nbsp; onComplete:showResult<br \/>\n};<br \/>\nvar forecastRequest = new Ajax.Request(url , para);<br \/>\n}<\/p>\n<p>\/\/\u663e\u793a\u9884\u62a5\u7ed3\u679c <br \/>\nfunction showResult(originalRequest)<br \/>\n{<br \/>\n$(&quot;result&quot;).innerHTML = &quot;&quot;;<br \/>\nresultXML = originalRequest.responseXML;<br \/>\nforecastNodes = resultXML.getElementsByTagName(&quot;forecast_conditions&quot;);<br \/>\nfor(i=0;i&lt;forecastNodes.length;i++){<br \/>\n&nbsp; var oneNode = forecastNodes[i];<br \/>\n&nbsp; var weekday = getData( oneNode , &quot;day_of_week&quot;);<br \/>\n&nbsp; var low = getData( oneNode , &quot;low&quot;);<br \/>\n&nbsp; var high = getData( oneNode , &quot;high&quot;);<br \/>\n&nbsp; var icon = getData( oneNode , &quot;icon&quot;);<br \/>\n&nbsp; var result = document.createElement(&quot;div&quot;);<br \/>\n&nbsp; result.appendChild(document.createTextNode(weekday));<br \/>\n&nbsp; result.appendChild(document.createElement(&quot;br&quot;));<br \/>\n&nbsp; result.appendChild(document.createTextNode(&quot;\u6700\u4f4e\u6e29\u5ea6&quot;+low));<br \/>\n&nbsp; result.appendChild(document.createElement(&quot;br&quot;));<br \/>\n&nbsp; result.appendChild(document.createTextNode(&quot;\u6700\u9ad8\u6e29\u5ea6&quot;+high));<br \/>\n&nbsp; result.appendChild(document.createElement(&quot;br&quot;));<br \/>\n&nbsp; var image = document.createElement(&quot;img&quot;);<br \/>\n&nbsp; image.setAttribute(&quot;src&quot; , &quot;<a rel=\"nofollow\" href=\"http:\/\/www.Google.com&quot;+icon\">http:\/\/www.Google.com&quot;+icon<\/a>);<br \/>\n&nbsp; result.appendChild(image);<br \/>\n&nbsp; $(&quot;result&quot;).appendChild(result);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/\u53d6\u5f97\u6570\u636e\u503c<br \/>\nfunction getData(parentNode , nodeName)<br \/>\n{<br \/>\nreturn parentNode.getElementsByTagName(nodeName)[0].getAttribute(&quot;data&quot;);<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n&lt;body onLoad=&quot;getCity()&quot;&gt;<br \/>\n&lt;div id=&quot;selectcity&quot;&gt;<br \/>\n&lt;form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;&gt;<br \/>\n&lt;select name=&quot;city&quot; id=&quot;city&quot; onChange=&quot;forecast(this.value)&quot;&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&quot;&quot;&gt;\u9009\u62e9\u57ce\u5e02&lt;\/option&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/select&gt;&nbsp;&nbsp;&nbsp; <br \/>\n&nbsp; &lt;\/form&gt;<br \/>\n&lt;\/div&gt;<\/p>\n<p>&lt;div id=&quot;result&quot;&gt;<\/p>\n<p>&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>ASP\u6f14\u793a:http:\/\/www.knowsky.com\/tools\/tianqiyubao.asp<br \/>\n\u6ce8\u610f\u8fd9\u6bb5\u4ee3\u7801\u5728IE\u4e0b\u53ef\u4ee5\u4f7f\u7528\uff0c\u5728IE\u91ccXMLHTTPREQUEST\u53ef\u4ee5\u9009\u62e9\u5141\u8bb8\u8de8\u57df\u3002<br \/>\n\u5728FF\u4e0b\uff0c\u5c31\u4e0d\u80fd\u4f7f\u7528\u4e86:(<br \/>\n\u89e3\u51b3\u529e\u6cd5\uff1a\u4f60\u53ef\u4ee5\u5148\u7528PHP\u8bfb\u4e0b\u6765Google\u63d0\u4f9b\u7684\u6570\u636e\uff0c\u518d\u7528XML\u5f62\u5f0f\u63d0\u4f9b\u7ed9\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u5c31\u53ef\u4ee5\u5566\u3002<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528prototype\u548cGoogle\u7684weather api\u505a\u5929\u6c14\u9884\u62a5 \u60f3\u62ffprototype\u7ec3\u7ec3\u624b\uff0c\u5c31\u7528prototype\u505a\u4e2a\u5929\u6c14\u9884\u62a5\u5427\u3002 Google Weather API \u53ea\u652f\u6301\u7f8e\u56fd\u5730\u533a\u4f7f\u7528\u90ae\u653f\u7f16\u7801\u8fdb\u884c\u67e5\u8be2,\u4f8b\u5982: http:\/\/w&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=749"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":66612,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/749\/revisions\/66612"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=749"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}