i have no idea on what's happen error, please me.
- the method geturl() undefined type httprequest
- the method createrequestfactory(new httprequestinitializer(){}) undefined type httptransport
- the constructor jsonhttpparser(jacksonfactory) undefined
am missing libraries?
thank you
import com.google.api.client.googleapis.googleheaders; import com.google.api.client.http.genericurl; import com.google.api.client.http.httprequest; import com.google.api.client.http.httprequestfactory; import com.google.api.client.http.httprequestinitializer; import com.google.api.client.http.httptransport; import com.google.api.client.http.javanet.nethttptransport; import com.google.api.client.http.json.jsonhttpparser; import com.google.api.client.json.jackson.jacksonfactory; public class googleplaces { /** global instance of http transport. */ private static final httptransport http_transport = new nethttptransport(); // google api key private static final string api_key = "my-api-key"; // google places serach url's private static final string places_search_url = "https://maps.googleapis.com/maps/api/place/search/json?"; private static final string places_text_search_url = "https://maps.googleapis.com/maps/api/place/search/json?"; private static final string places_details_url = "https://maps.googleapis.com/maps/api/place/details/json?"; private double _latitude; private double _longitude; private double _radius; /** * searching places * @param latitude - latitude of place * @params longitude - longitude of place * @param radius - radius of searchable area * @param types - type of place search * @return list of places * */ public placeslist search(double latitude, double longitude, double radius, string types) throws exception { this._latitude = latitude; this._longitude = longitude; this._radius = radius; 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); // in meters request.geturl().put("sensor", "false"); if(types != null) request.geturl().put("types", types); placeslist list = request.execute().parseas(placeslist.class); // check log cat places response status log.d("places status", "" + list.status); return list; } catch (httpresponseexception e) { log.e("error:", e.getmessage()); return null; } } /** * searching single place full details * @param refrence - reference id of place * - in search api request * */ public placedetails getplacedetails(string reference) throws exception { try { httprequestfactory httprequestfactory = createrequestfactory(http_transport); httprequest request = httprequestfactory .buildgetrequest(new genericurl(places_details_url)); request.geturl().put("key", api_key); request.geturl().put("reference", reference); request.geturl().put("sensor", "false"); placedetails place = request.execute().parseas(placedetails.class); return place; } catch (httpresponseexception e) { log.e("error in perform details", e.getmessage()); throw e; } } /** * 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("androidhive-places-test"); request.setheaders(headers); jsonhttpparser parser = new jsonhttpparser(new jacksonfactory()); request.addparser(parser); } }); } }
Comments
Post a Comment