2012-08-27 3 views
2

에서 다음 코드 작업을 날씨를 가져올 수 없습니다 :안드로이드는, 전에 잘 구글 API를

class RetreiveWeatherTask extends AsyncTask<Bundle, Void, WeatherData> { 

     private static final String TAG = "WeatherManager"; 

     @Override 
     protected WeatherData doInBackground(Bundle... params) { 
      Utils.log(TAG, "start get weather"); 
      WeatherData weatherData = new WeatherData(); 
      Bundle b = new Bundle(params[0]); 
      double latitude = b.getDouble(REF_LAT); 
      double longtitude = b.getDouble(REF_LONG); 

      try 
      { 
       StringBuilder weatherBuilder = new StringBuilder(); 
       //weatherBuilder.append("http://www.google.com/ig/api?hl=zh-cn&weather=,,,"); 
       weatherBuilder.append("http://www.google.com/ig/api?hl=en-us&weather=,,,"); 
       int la = (int) latitude * 1000000; 
       int lo = (int) longtitude * 1000000; 
       weatherBuilder.append(la); 
       weatherBuilder.append(","); 
       weatherBuilder.append(lo); 
       String weather = weatherBuilder.toString(); 
       HttpGet hg = new HttpGet(weather); 
       // HttpGet hg = new 
       // HttpGet("http://www.google.com/ig/api?hl=zh-cn&weather=,,,39130000,117200000"); 
       HttpClient hc = new DefaultHttpClient(); 
       HttpResponse hr = hc.execute(hg); 
       String responseString = ""; 
       if (hr.getStatusLine().getStatusCode() != HttpStatus.SC_OK) 
       { 
        Utils.logi("", "Location != HttpStatus.SC_OK"); 
        return null; 
       } 
       responseString = EntityUtils.toString(hr.getEntity()); 
       InputStream is = new ByteArrayInputStream(responseString.getBytes()); 

       // URL url = new 
       // URL("http://www.google.com/ig/api?hl=zh-cn&weather=,,,39130000,117200000"); 
       // InputStream is =url.openStream(); 
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
       DocumentBuilder db = dbf.newDocumentBuilder(); 
       Document document = db.parse(is); 

       NodeList currList = (NodeList) document.getElementsByTagName("current_conditions"); 
       NodeList currList2 = currList.item(0).getChildNodes(); 

       weatherData.weather = new String(currList2.item(0).getAttributes().item(0).getNodeValue()); 

       weatherData.curTemperature = new String(currList2.item(2).getAttributes().item(0).getNodeValue() + "℃"); 

       weatherData.wind = new String(currList2.item(5).getAttributes().item(0).getNodeValue()); 

       Utils.log(TAG, "Get weather = " + weatherData.weather); 
       if (isNeedIconFromNet) 
       { 
        weatherData.iconUrl = new String(currList2.item(4).getAttributes().item(0).getNodeValue()); 


        String url = "http://www.google.com" + weatherData.iconUrl; 
        weatherData.icon = getBitmapByUrl(url); 
       } 

      } 
      catch (Exception e) 
      { 
       Utils.logi("", "Location get temp Exception e"); 
       e.printStackTrace(); 
      } 

      return weatherData; 
     } 

하지만 지금은 문자열 반환 : 지원되지 않는 API를.

도와주세요. Google API가 닫혔습니까? PS. 나는 중국에있다.

답변

3

예, Google에서 문서화되지 않은 날씨 API 서비스를 중단 한 것으로 보입니다.

XML Parsing Error: syntax error 
Location: http://www.google.com/ig/api?weather=delhi 
Line Number 1, Column 1:Unsupported API 
^ 

당신은 yahoo weather 또는 http://www.wunderground.com/weather/api을 시도 할 수 있습니다. 그러나 Yahoo는 약 2 일간의 일기 예보를 제공하는 반면 (야후에서 간접적으로 예측 한 날 수를 늘릴 수있는 다른 방법이있을 수 있음) 약 4 일간 일기 예보를 제공합니다.

1

Google 날씨 API의 끝이 왔으며 Google이 서비스를 중지했다고 생각합니다. 결국 공식적으로 지원되는 API조차도 아니 었습니다.

iGoogle에서 더 이상 API를 사용하지 않는 것 같습니다. 가장 좋은 옵션은 아마도 다른 무료 날씨 API를 찾는 것입니다.

앞으로 며칠 동안이 변경 사항에 대해 더 자세히 알게 될 것입니다.