2012-10-13 44 views
1

我以前從未使用Google Places,並認爲是時候這樣做了。 我已經按照這個教程:http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/Android - 試圖實施Google Places API

我的問題是,當我創建這個方法createRequestFactory()它說,JsonHttpParser類現在已經過時。我到處尋找替代解決方案,但一直未能如此。我針對Android 2.1並在Eclipse Juno中開發。有沒有人有任何線索如何解決這場衝突?我沒有收到任何編譯錯誤,並且eclipse正在構建它,沒有任何問題,但我不想使用這個已棄用的類。

這裏是我的代碼:

public static HttpRequestFactory createRequestFactory(
     final HttpTransport transport) { 
    return transport.createRequestFactory(new HttpRequestInitializer() { 
     public void initialize(HttpRequest request) { 
      GoogleHeaders headers = new GoogleHeaders(); 
      headers.setApplicationName("AndroidHive-Places-Test"); 
      request.setHeaders(headers); 
      // deprecated this last two lines 
      JsonHttpParser parser = new JsonHttpParser(new JacksonFactory()); 
      request.addParser(parser); 
     } 
    }); 
} 

提前感謝!

回答

1
try{ 
    HttpPost httppost = new HttpPost(googleSearchPlaceUrl); 
    HttpClient httpclient = new DefaultHttpClient(); 
    response = httpclient.execute(httppost); 
    String data = EntityUtils.toString(response.getEntity()); 
    //parse with Json 

} catch (Exception e) { 
    e.printStackTrace(); 
} 
+0

你能解釋一下你的答案嗎? –

0

你必須使用JsonObjectParser而不是JsonHttpParser

JsonObjectParser parser = new JsonObjectParser(new JacksonFactory()); 
+0

我試過了,但是該方法addParser需要一個HttpParser(JsonHttpParser)。 – Carnal

+0

您的項目中使用了哪個版本的api? – Tkingovr

+0

「google-http-client」,「google-http-client-android2」,「google-api-client」和「google-api-client-android2」1.11.0-beta – Carnal