2010年10月6日 星期三

一些 Google 天氣氣象用 API

取得台灣區域城市的經緯度 www.google.com/ig/cities?output=xml&hl=zh-tw&country=tw

傳回結果如

<xml_api_reply version="1">
<cities>
<city><name data="台中"/><latitude_e6 data="24150187"/><longitude_e6 data="120642999"/></city>
<city default="true" ><name data="台北"/><latitude_e6 data="25091075"/><longitude_e6 data="121559834"/></city>
<city><name data="台東"/><latitude_e6 data="22984612"/><longitude_e6 data="120987632"/></city>
<city><name data="台南"/><latitude_e6 data="23005897"/><longitude_e6 data="120182022"/></city>
<city><name data="宜蘭"/><latitude_e6 data="24692947"/><longitude_e6 data="121719546"/></city>
<city><name data="花蓮"/><latitude_e6 data="23756899"/><longitude_e6 data="121354163"/></city>
<city><name data="金門"/><latitude_e6 data="24454650"/><longitude_e6 data="118380432"/></city>
<city><name data="南投"/><latitude_e6 data="23838760"/><longitude_e6 data="120987632"/></city>
<city><name data="屏東"/><latitude_e6 data="22549506"/><longitude_e6 data="120619990"/></city>
<city><name data="恆春"/><latitude_e6 data="21977337"/><longitude_e6 data="120746490"/></city>
<city><name data="苗栗"/><latitude_e6 data="24489269"/><longitude_e6 data="120941737"/></city>
<city><name data="桃園"/><latitude_e6 data="24937587"/><longitude_e6 data="121216847"/></city>
<city><name data="馬祖"/><latitude_e6 data="26158211"/><longitude_e6 data="119928474"/></city>
<city><name data="高雄"/><latitude_e6 data="22625108"/><longitude_e6 data="120308954"/></city>
<city><name data="基隆"/><latitude_e6 data="25108981"/><longitude_e6 data="121708145"/></city>
<city><name data="雲林"/><latitude_e6 data="23755852"/><longitude_e6 data="120389665"/></city>
<city><name data="新竹"/><latitude_e6 data="24803945"/><longitude_e6 data="120964687"/></city>
<city><name data="嘉義"/><latitude_e6 data="23475449"/><longitude_e6 data="120447285"/></city>
<city><name data="彰化"/><latitude_e6 data="23992974"/><longitude_e6 data="120481845"/></city>
<city><name data="澎湖"/><latitude_e6 data="23565479"/><longitude_e6 data="119615143"/></city>
<city><name data="蘭嶼"/><latitude_e6 data="22043562"/><longitude_e6 data="121548418"/></city>
</cities>
</xml_api_reply>

取得指定城市的天氣資訊 www.google.com/ig/api?weather=Taipei 傳回結果如
<xml_api_reply version="1">
 <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
 <forecast_information>
  <city data="Taipei"/>
  <postal_code data="Taipei"/>
  <latitude_e6 data=""/>
  <longitude_e6 data=""/>
  <forecast_date data="2010-10-06"/>
  <current_date_time data="2010-10-06 17:00:00 +0000"/>
  <unit_system data="SI"/>
 </forecast_information>
 <current_conditions>
  <condition data="陰"/>
  <temp_f data="78"/>
  <temp_c data="26"/>
  <humidity data="濕度: 63%"/>
  <icon data="/ig/images/weather/cloudy.gif"/>
  <wind_condition data="風向:  公里/小時"/>
 </current_conditions>
 <forecast_conditions>
  <day_of_week data="週三"/>
  <low data="23"/>
  <high data="28"/>
  <icon data="/ig/images/weather/cloudy.gif"/>
  <condition data="多雲"/>
 </forecast_conditions>
 <forecast_conditions>
  <day_of_week data="週四"/>
  <low data="23"/>
  <high data="30"/>
  <icon data="/ig/images/weather/cloudy.gif"/>
  <condition data="多雲"/>
 </forecast_conditions>
 <forecast_conditions>
  <day_of_week data="週五"/>
  <low data="24"/>
  <high data="30"/>
  <icon data="/ig/images/weather/rain.gif"/>
  <condition data="多雲轉陰短暫雨"/>
 </forecast_conditions>
 <forecast_conditions>
  <day_of_week data="週六"/>
  <low data="23"/>
  <high data="27"/>
  <icon data="/ig/images/weather/rain.gif"/>
  <condition data="陰短暫雨"/>
 </forecast_conditions>
 </weather>
</xml_api_reply>

也可以搭配經緯度取得城市的天氣 http://www.google.com/ig/api?hl=zh-tw&weather=,,,24150187,120642999 (台中)傳回結果如

<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data=""/>
<postal_code data=""/>
<latitude_e6 data="24150187"/>
<longitude_e6 data="120642999"/>
<forecast_date data="2010-10-06"/>
<current_date_time data="2010-10-06 17:00:00 +0000"/>
<unit_system data="SI"/>
</forecast_information>
<current_conditions>
<condition data="陰有霾"/>
<temp_f data="83"/>
<temp_c data="28"/>
<humidity data="濕度: 69%"/>
<icon data="/ig/images/weather/haze.gif"/>
<wind_condition data="風向:  公里/小時"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="週三"/>
<low data="22"/><high data="30"/>
<icon data="/ig/images/weather/cloudy.gif"/>
<condition data="多雲"/></forecast_conditions>
<forecast_conditions>
<day_of_week data="週四"/>
<low data="23"/>
<high data="31"/>
<icon data="/ig/images/weather/cloudy.gif"/>
<condition data="多雲"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="週五"/>
<low data="24"/>
<high data="31"/>
<icon data="/ig/images/weather/rain.gif"/>
<condition data="多雲轉陰短暫雨"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="週六"/>
<low data="23"/><high data="30"/>
<icon data="/ig/images/weather/rain.gif"/>
<condition data="陰時多雲短暫雨"/>
</forecast_conditions>
</weather>
</xml_api_reply>

推薦 Google Chrome Extension 教學

剛剛在找Chrome Extension如何對外做跨網域請求,google路過了這篇

[教學]學習撰寫 Google Chrome Extension

還有附範例檔,推薦有興趣的人來學習!!

2010年10月4日 星期一

監視DOM的copy, paste事件 (oncopy, onpaste event)


根據 http://en.wikipedia.org/wiki/DOM_events 的說明


Two major types of events are added by Microsoft, and in some cases can only be used in Internet Explorer. Others have been implemented as de-facto standards by other browsers.

Microsoft在自家的ie瀏覽器上,多自訂了以上兩種類型的事件,其中oncopy, onpaste這兩個,上週發現Firefox 3.6, Chrome 6都也可以支援。

document.getElementById(ElementID).addEventListener(eventType, fn);

eventType為'copy' 或是'paste', fn為function.

雖然不是W3C的規格,但這個監視剪貼簿的事件真的不錯用,省去監視keyup/keypress/keydown或是按滑鼠右鍵複製貼上這些實作。