Reputation: 11
Im developing an application that simply shows the nearby places to my location and i have implemented the map layout and got my location. i have used this blog http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html
in order to retrieve the places nearby but there is one problem i cant solve in this method
private static final HttpTransport transport = AndroidHttp .newCompatibleTransport(); 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-DemoApp");
request.setHeaders(headers);
JsonHttpParser parser = new JsonHttpParser();
parser.jsonFactory = new JacksonFactory();
request.addParser(parser);
}
});
}
which simply does open an http connection to execute the search url
the problem is that at parser.jsonFactory = new JacksonFactory(); eclipse tell me that The field JsonHttpParser.jsonFactory is not visible. how can i solve this issue knowing that i have imported all necessary external jars.
Thank you
Upvotes: 1
Views: 785
Reputation: 2563
It appears that Class JsonHttpParser and Method HttpRequest were both deprecated in version 1.11. See The Deprecated list for more information.
So instead of:
JsonHttpParser parser = new JsonHttpParser();
parser.jsonFactory = new JacksonFactory();
request.addParser(parser);
Try:
JsonObjectParser parser = new JsonObjectParser(new JacksonFactory());
request.setParser(parser);
And use import:
import com.google.api.client.json.JsonObjectParser;
Note: Not tested.
Upvotes: 0
Reputation: 1530
I experienced the same problem before.
This is because the jsonFactory and headers variables are depracated since 1.6. If you are using Google APIs before 1.6 version, it should work properly.
Check this for more info:
You need to devise alternate methods to be used.
Use the below re-framed code:
GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("Google-Places-DemoApp");
request.setHeaders(headers);
request.addParser(new JsonHttpParser(new JacksonFactory()));
Note: Not tested!
Upvotes: 1