我正在使用 google places API,在解析中我使用的是 JSON,但是这一行
JsonHttpParser parser = new JsonHttpParser(new JacksonFactory());
request.addParser(parser);
已弃用。有什么方法可以修复或任何替代方法吗?
这是功能:
public Placeslist search(double latitude, double longitude, double radius, String types)
throws Exception {
try {
HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
HttpRequest request = httpRequestFactory
.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
request.getUrl().put("key", API_KEY);
request.getUrl().put("location", _latitude + "," + _longitude);
request.getUrl().put("radius", _radius);
request.getUrl().put("sensor", "false");
if(types != null)
request.getUrl().put("types", types);
Placeslist list = request.execute().parseAs(Placeslist.class);
// Check log cat for places response status
Log.d("Places Status", "" + list.status);
return list;
} catch (HttpResponseException e) {
Log.e("Error:", e.getMessage());
return null;
}
}
// Creating http request Factory
public static HttpRequestFactory createRequestFactory(
final HttpTransport transport) {
return transport.createRequestFactory(new HttpRequestInitializer() {
public void initialize(HttpRequest request) {
GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("Google-Places-Test");
request.setHeaders(headers);
JsonHttpParser parser = new JsonHttpParser(new JacksonFactory());
request.addParser(parser);
}
});
}