2013-01-14 1 views

답변

1

Yahoo! PlaceFinder API을 사용하여 WOEID를 가져올 수 있습니다. 첫째로 당신은 당신이 같은 요청을 보낼 수있는 API 키를 요청해야합니다

http://where.yahooapis.com/geocode?q=[search query]&appid=[yourappidhere] 

당신은 응답으로이 얻을 것이다 :

<ResultSet xmlns:ns1="http://www.yahooapis.com/v1/base.rng" version="2.0" xml:lang="en-US"> 
<Error>0</Error> 
<ErrorMessage>No error</ErrorMessage> 
<Locale>en-US</Locale> 
<Found>1</Found> 
<Quality>85</Quality> 
<Result> 
<quality>85</quality> 
<latitude>38.898708</latitude> 
<longitude>-77.036369</longitude> 
<offsetlat>38.89719</offsetlat> 
<offsetlon>-77.036537</offsetlon> 
<radius>400</radius> 
<name/> 
<line1>1600 Pennsylvania Ave NW</line1> 
<line2>Washington, DC 20500-0005</line2> 
<line3/> 
<line4>United States</line4> 
<house>1600</house> 
<street>Pennsylvania Ave NW</street> 
<xstreet/> 
<unittype/> 
<unit/> 
<postal>20500-0005</postal> 
<neighborhood/> 
<city>Washington</city> 
<county>District of Columbia</county> 
<state>District of Columbia</state> 
<country>United States</country> 
<countrycode>US</countrycode> 
<statecode>DC</statecode> 
<countycode>DC</countycode> 
<uzip>20500</uzip> 
<hash>4216F67AA1A143E9</hash> 
<woeid>12766118</woeid> // This is what you need 
<woetype>11</woetype> 
</Result> 
</ResultSet> 

당신은 <woeid> 태그의 응답을 구문 분석 할 수 있습니다.

편집 : 당신이 글고 치기가 있고 당신이 그의 입력에서 얻을 도시를 기반으로 날씨를 얻고 싶다면
다음이해야 할 것이다 : 이제

String searchQuery = Uri.encode(myEditText.getText().toString()); 

당신 ' 당신의 수색 질문이있을 것이다. 에서 사용자 유형의 경우 예컨대 그래서 :

함부르크 독일

는 다음이로 변환됩니다

Hamburg_Germany

+1

는 응답 RSS 피드입니다. 그렇지 않다면 어떻게 읽습니까? – AndroidDev

+1

이것은 XML 응답이므로 XML 구문 분석기 (DOM, SAX 또는 pullparser)를 사용하여 구문 분석 할 수 있습니다. – Ahmad

+0

[search query]는 무엇이 들어 있습니까? – AndroidDev