2015年9月21日 星期一
2014年5月19日 星期一
經YQL由經緯度找woeid的方法
感謝底下作者找到yahoo api 找woeid的方法
ref:http://wcn2002.pixnet.net/blog/post/115070251-ios-app%E9%96%8B%E7%99%BC(2)
經由經緯度可得到相對應的地點的woeid值
http://query.yahooapis.com/v1/public/yql?q=select woeid from geo.placefinder where text="37.416275,-122.025092" and gflags="R"
節錄:
"Lat/Lon可以藉由LBS取得,
所以整個就很清楚簡單了,
1.透過LBS取得所在位子的Lat/Lon
2.透過Yahoo AP query並根據1的結果取得WOEID
3.透過Yahoo weather API及根據2的WOEID取得天氣資訊"
2014年5月17日 星期六
解析XML前下載檔案
參考Mars的方式為了要下載檔案,獨立寫了一個類別HttpDownloader.java 方便以後的引用
避免不必要的重複代碼
HttpDownloader.java
------------------------------------------------
public class HttpDownloader {
private URL myurl=null;
public String download(String urlstr){
StringBuffer sb=new StringBuffer();
String line=null;
BufferedReader buffer= null;
try {
myurl = new URL(urlstr);
HttpsURLConnection con= (HttpsURLConnection) myurl.openConnection();
con.connect();
buffer=new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line=buffer.readLine())!=null) {
//sb.append(line);
sb.append(line);
//System.out.println("testest");
//System.out.println(sb.toString());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
buffer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return sb.toString();
}
}
-----------------------------------
然後要使用時,在MainActivity.java使用
MainActivity.java
-----------------------------------
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Button btGetxml=(Button)findViewById(R.id.button1);
btGetxml.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TextView tv1=(TextView)findViewById(R.id.tv1);
HttpDownloader httpDownloader=new HttpDownloader();
String getxml=httpDownloader.download("https://weather.yahooapis.com/forecastrss?w=2306179");
System.out.println(getxml);
//tv1.setText(getxml);
try {
//使用DOM解析XML
DocumentBuilderFactory dfactory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dfactory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(getxml)));
//
使用DOM解析XML
此處示範基本解析XML單項解析方式
當然接下來可以用自己的方式來遍歷解析
yahoo weather api
https://weather.yahooapis.com/forecastrss?w=2306179
<item>
<title>Conditions for Taipei City, TW at 11:29 pm CST</title>
<geo:lat>25.09</geo:lat>
<geo:long>121.56</geo:long>
<link>
http://us.rd.yahoo.com/dailynews/rss/weather/Taipei_City__TW/*http://weather.yahoo.com/forecast/TWXX0021_f.html
</link>
<pubDate>Sat, 17 May 2014 11:29 pm CST</pubDate>
<yweather:condition text="Mostly Cloudy" code="27" temp="81" date="Sat, 17 May 2014 11:29 pm CST"/>
<description>
<![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/27.gif"/><br /> <b>Current Conditions:</b><br /> Mostly Cloudy, 81 F<BR /> <BR /><b>Forecast:</b><BR /> Sat - Partly Cloudy. High: 86 Low: 77<br /> Sun - PM Thundershowers. High: 86 Low: 75<br /> Mon - Thunderstorms. High: 82 Low: 75<br /> Tue - Thunderstorms. High: 87 Low: 74<br /> Wed - Rain. High: 80 Low: 74<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Taipei_City__TW/*http://weather.yahoo.com/forecast/TWXX0021_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]>
</description>
<yweather:forecast day="Sat" date="17 May 2014" low="77" high="86" text="Partly Cloudy" code="29"/>
<yweather:forecast day="Sun" date="18 May 2014" low="75" high="86" text="PM Thundershowers" code="39"/>
<yweather:forecast day="Mon" date="19 May 2014" low="75" high="82" text="Thunderstorms" code="4"/>
<yweather:forecast day="Tue" date="20 May 2014" low="74" high="87" text="Thunderstorms" code="4"/>
<yweather:forecast day="Wed" date="21 May 2014" low="74" high="80" text="Rain" code="12"/>
<guid isPermaLink="false">TWXX0021_2014_05_21_7_00_CST</guid>
</item>
---------------------------------------
//使用DOM解析XML
DocumentBuilderFactory dfactory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dfactory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(getxml)));
//doc.getDocumentElement().normalize();
//先get到你要的tag吧,記得回傳型態是NodeList,
NodeList Node1=doc.getElementsByTagName("yweather:location");
NodeList Node2=doc.getElementsByTagName("yweather:forecast");
NodeList Node_item=doc.getElementsByTagName("item");
String value1=Node1.item(0).getAttributes().item(0).getNodeValue();
String value2=Node1.item(0).getAttributes().item(2).getNodeValue();
String value3=Node2.item(1).getAttributes().item(3).getNodeValue();
String value4=Node2.item(2).getAttributes().item(3).getNodeValue();
String v_item=Node_item.item(0).getChildNodes().item(1).getFirstChild().getNodeName();
//需注意的是選了節點 getChildNodes().item(1)後還需要加.getFirstChild()才行
String v_item2=Node_item.item(0).getFirstChild().getNodeValue();
System.out.println("value"+value1);
tv1.setText(value1+value2+"value3 "+value3+"value4 "+value4+"v_item "+v_item+"value6 "+v_item2);
結果顯示:
其中getFirstChilid的問題可參考網址:
http://www.ogshoppingmall.com/list.asp?id=48665
其中一段:.
當一個Node對象被建立之后,保存在XML文檔中的數據就被提取出來并封裝在這個Node中了。在這個例子中,要提取Message標簽內的內容,我們通常會使用Node對象的getNodeValue()方法:
String message = my_node.getFirstChild().getNodeValue();
請注意,這里還使用了一個getFirstChild()方法來獲得message下面的第一個子Node對象。雖然在message標簽下面除了文本外并沒有其它子標簽或者屬性,但是我們堅持在這里使用getFirseChild()方法,這主要和W3C對DOM的定義有關。W3C把標簽內的文本部分也定義成一個Node,所以先要得到代表文本的那個Node,我們才能夠使用getNodeValue()來獲取文本的內容。現在,既然我們已經能夠從XML文件中提取出數據了,我們就可以把這些數據用在合適的地方,來構筑應用程序。
2013年5月1日 星期三
cocos2dx 設定
超感謝Tim Chang部落格的教學
http://kw0006667.wordpress.com/2013/04/25/cocos2d-x-%E9%96%8B%E7%99%BC-android-app/
以及子龍山人
http://www.cnblogs.com/zilongshanren/archive/2012/04/28/2473282.html
的教學
但是仍舊在Eclipse project前面還有紅色叉叉
即使是裡面都沒有紅色叉叉提示
花了千辛萬苦才找到原因
後來陸續發現幾個步驟還沒補齊
1.需要設定 環境變數(Envoirment vaiable)的路徑加入 c:/cygwin/bin
在我的電腦-->內容-->進階-->環境變數-->系統變數-->path(加入c:/cygwin/bin路徑)
2.需要在加入三個路徑
a. 對project選 Properties\C/C++ General\Paths and Symbols\Source location.
Lined to $COCOS2DX_HOME/cocos2dx
b.對project選 Properties\C/C++ General\Path and Symbols\GNU C++. Add$(COCOS2DX_HOME)/CocosDenshion/include
c.對project選 Properties\C/C++ General\Path and Symbols\GNU C++. Add$(COCOS2DX_HOME)/cocos2dx
紅色叉叉就消失了~ :)
2013年2月16日 星期六
[Cafe shop][Taichung]ALLO art Gallery Cafe(20130214)
This place is my friend Ansel recommend me, and he found it in internet.
He is always has full of good restaurant list,and I always can got some good place to go.
Tonight is still during of the Chinese new year time,and we drive fool around the Taichung city,try to seize the last vaction of tail.
We follow the google map's instruction and arrive in the alley.
It's quite a relax place
Stuff on the manu is not expensive nor cheap. (About NT150/ 1 cup)
Beautiful interior decoration,and nice waiter
Tonight stay here and chat with friends is a very wonderful things. :)
台中市西區精誠五街32號
AM11:00~PM23:00 (Tuesday off.)
TEL:+886-4-2320-3590
2013年2月4日 星期一
[桃園][食記]大方蘭州拉麵館-有點感動的手工麵(20130204)
今天一夥四人無聊殺到Ikea殺時間,到了晚餐時間google了一下,
挑了一間網路上名店"大方蘭州拉麵館"
到現場跟我想像的拉麵店有落差,就是傳統小吃店的店鋪
反正就是殺進去吃,老板規定看電視只能看卡通台,老闆人很熱情解釋為什麼只看卡通台
不過結論是食物算是很好吃,而且麵條是現做,實在很有誠意,而且吃起來算是Q中帶硬的感覺
我個人覺得這種拉麵是上品
吃的時候還感受到麵條粗細不一,這只有手工麵才有的感動~(一碗最貴的160值得)
在我牛肉麵清單中只有老兄牛肉麵超越他
桃園市永安路389號之2
03-331-4193
最晚開到晚上十點
