android - Google Places Error -
i'm trying perform search using google places api in app i'm getting error.
my code:
public class googleplaces { /** global instance of http transport. */ private static final httptransport http_transport = new nethttptransport(); private static final string 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_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 ; 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 * @paramrefrence - 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 detail", 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("com-xink-vn"); request.setheaders(headers); jsonhttpparser parser = new jsonhttpparser(new jacksonfactory()); request.addparser(parser); } }); } }
error log:
java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:299) @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) @ java.util.concurrent.futuretask.setexception(futuretask.java:124) @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) @ java.util.concurrent.futuretask.run(futuretask.java:137) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) @ java.lang.thread.run(thread.java:856) caused by: java.lang.noclassdeffounderror: com.google.common.base.preconditions @ com.google.api.client.util.classinfo.<init>(classinfo.java:164) @ com.google.api.client.util.classinfo.of(classinfo.java:92) @ com.google.api.client.util.genericdata.<init>(genericdata.java:79) @ com.google.api.client.util.genericdata.<init>(genericdata.java:61) @ com.google.api.client.http.genericurl.<init>(genericurl.java:97) @ com.vog.utils.googleplaces.search(googleplaces.java:59) @ com.vog.xink.editpictureactivity$loadplaces.doinbackground(editpictureactivity.java:606) @ com.vog.xink.editpictureactivity$loadplaces.doinbackground(editpictureactivity.java:576) @ android.os.asynctask$2.call(asynctask.java:287) @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) at java.util.concurrent.futuretask.run(futuretask.java:137) at android.os.asynctask$serialexecutor$1.run(asynctask.java:230) at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) at java.lang.thread.run(thread.java:856)
Comments
Post a Comment