android - Search nearby places using AutoCompleteTextView -
i want show list of nearby places using autocompletetextview https://www.google.co.in/maps/@12.9539974,77.6309395,11z?hl=en , want show icon of places facebook checkin, when search word atm shows nearby atm in list , icon, possible implement in app? if yes how? can me?
my code below:
findplaces.java
public class findplaces extends appcompatactivity implements locationlistener, googleapiclient.onconnectionfailedlistener { private googleapiclient mgoogleapiclient; private static final latlngbounds bounds_greater_sydeny = new latlngbounds( new latlng(23.0396, 72.566), new latlng(23.0396, 72.566));//23.0396,72.566 private autocompletetextview mautocompleteview; private activity mactivity; private imageview imgsearchclear; private string searchaddress = ""; private placeautocompleteadapter madapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mgoogleapiclient = new googleapiclient.builder(this) .enableautomanage(this, 0 /* clientid */, this) .addapi(places.geo_data_api).build(); setcontentview(r.layout.find_place); mactivity = findplaces.this; mautocompleteview = (autocompletetextview) findviewbyid(r.id.edtsearch); mautocompleteview.setonitemclicklistener(mautocompleteclicklistener); imgsearchclear = (imageview) findviewbyid(r.id.imgsearchclear); imgsearchclear.setvisibility(view.gone); madapter = new placeautocompleteadapter(this, mgoogleapiclient, bounds_greater_sydeny, null); mautocompleteview.setadapter(madapter); mautocompleteview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { if (webinterface.isonline(mactivity)) { v.setfocusable(true); v.setfocusableintouchmode(true); } else { v.setfocusable(false); v.setfocusableintouchmode(false); } return false; } }); imgsearchclear.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mautocompleteview.settext(""); } }); mautocompleteview.setoneditoractionlistener(new textview.oneditoractionlistener() { @override public boolean oneditoraction(textview v, int actionid, keyevent event) { if (actionid == editorinfo.ime_action_search) { // performsearch(); return true; } return false; } }); mautocompleteview.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { if (webinterface.isonline(mactivity)) { mautocompleteview.setfocusable(true); if (!mautocompleteview.gettext().tostring().equals("")) { imgsearchclear.setvisibility(view.visible); } else { imgsearchclear.setvisibility(view.gone); } } else { } } @override public void aftertextchanged(editable s) { } }); } @override public void onlocationchanged(location location) { } @override public void onstatuschanged(string provider, int status, bundle extras) { } @override public void onproviderenabled(string provider) { } @override public void onproviderdisabled(string provider) { } @override public void onconnectionfailed(@nonnull connectionresult connectionresult) { } private adapterview.onitemclicklistener mautocompleteclicklistener = new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { /* * retrieve place id of selected item adapter. * adapter stores each place suggestion in autocompleteprediction * read place id , title. */ inputmethodmanager imm = (inputmethodmanager) getsystemservice(context.input_method_service); imm.hidesoftinputfromwindow(view.getapplicationwindowtoken(), 0); mautocompleteview.clearfocus(); final autocompleteprediction item = madapter.getitem(position); final string placeid = item.getplaceid(); final charsequence primarytext = item.getprimarytext(null); log.d("autocomplete item item: ", item.getdescription()); log.d("autocomplete item placeid: ", placeid); log.d("autocomplete item selected: ", primarytext + ""); try { searchaddress = urldecoder.decode(item.getdescription().tostring(), "utf-8"); } catch (unsupportedencodingexception e) { e.printstacktrace(); } /* * issue request places geo data api retrieve place * object additional details place. */ pendingresult<placebuffer> placeresult = places.geodataapi .getplacebyid(mgoogleapiclient, placeid); placeresult.setresultcallback(mupdateplacedetailscallback); } }; private resultcallback<placebuffer> mupdateplacedetailscallback = new resultcallback<placebuffer>() { @override public void onresult(placebuffer places) { if (!places.getstatus().issuccess()) { // request did not complete log.d("place query did not complete. error: " , places.getstatus().tostring()); places.release(); return; } // place object buffer. final place place = places.get(0); // format details of place display , show in // textview. log.d("full address", place.getaddress().tostring()); string latlong = place.getlatlng().tostring(); string s = ""; s = latlong.substring(latlong.indexof("(") + 1); s = latlong.substring(0, latlong.indexof(")")); string split[] = s.split(","); log.d("place details received: ", place.getname() + ""); // mlocation = place.getname(); places.release(); } }; }
placeautocompleteadapter.java
public class placeautocompleteadapter extends arrayadapter<autocompleteprediction> implements filterable { private static final string tag = "placeautocompleteadapter"; private static final characterstyle style_bold = new stylespan(typeface.bold); /** * current results returned adapter. */ private arraylist<autocompleteprediction> mresultlist; /** * handles autocomplete requests. */ private googleapiclient mgoogleapiclient; /** * bounds used places geo data autocomplete api requests. */ private latlngbounds mbounds; /** * autocomplete filter used restrict queries specific set of place types. */ private autocompletefilter mplacefilter; /** * initializes resource text rows , autocomplete query bounds. * * @see arrayadapter#arrayadapter(context, int) */ public placeautocompleteadapter(context context, googleapiclient googleapiclient, latlngbounds bounds, autocompletefilter filter) { super(context, r.layout.map_data_row, android.r.id.text1); mgoogleapiclient = googleapiclient; mbounds = bounds; mplacefilter = filter; } /** * sets bounds subsequent queries. */ public void setbounds(latlngbounds bounds) { mbounds = bounds; } /** * returns number of results received in last autocomplete query. */ @override public int getcount() { if (mresultlist != null) return mresultlist.size(); else return 0; } /** * returns item last autocomplete query. */ @override public autocompleteprediction getitem(int position) { return mresultlist.get(position); } @override public view getview(int position, view convertview, viewgroup parent) { view row = super.getview(position, convertview, parent); // sets primary , secondary text row. // note getprimarytext() , getsecondarytext() return charsequence may contain // styling based on given characterstyle. autocompleteprediction item = getitem(position); textview textview1 = (textview) row.findviewbyid(android.r.id.text1); textview textview2 = (textview) row.findviewbyid(android.r.id.text2); textview1.settext(item.getprimarytext(style_bold)); textview2.settext(item.getsecondarytext(style_bold)); return row; } /** * returns filter current set of autocomplete results. */ @override public filter getfilter() { return new filter() { @override protected filterresults performfiltering(charsequence constraint) { filterresults results = new filterresults(); // skip autocomplete query if no constraints given. if (constraint != null) { // query autocomplete api (constraint) search string. mresultlist = getautocomplete(constraint); if (mresultlist != null) { // api returned results. results.values = mresultlist; results.count = mresultlist.size(); } } return results; } @override protected void publishresults(charsequence constraint, filterresults results) { if (results != null && results.count > 0) { // api returned @ least 1 result, update data. notifydatasetchanged(); } else { // api did not return results, invalidate data set. notifydatasetinvalidated(); } } @override public charsequence convertresulttostring(object resultvalue) { // override method display readable result in autocompletetextview // when clicked. if (resultvalue instanceof autocompleteprediction) { return ((autocompleteprediction) resultvalue).getfulltext(null); } else { return super.convertresulttostring(resultvalue); } } }; } private arraylist<autocompleteprediction> getautocomplete(charsequence constraint) { if (mgoogleapiclient.isconnected()) { log.d("starting autocomplete query for: ", constraint + ""); // submit query autocomplete api , retrieve pendingresult // contain results when query completes. pendingresult<autocompletepredictionbuffer> results = places.geodataapi .getautocompletepredictions(mgoogleapiclient, constraint.tostring(), mbounds, mplacefilter); // method should have been called off main ui thread. block , wait @ 60s // result api. autocompletepredictionbuffer autocompletepredictions = results .await(60, timeunit.seconds); // confirm query completed successfully, otherwise return null final status status = autocompletepredictions.getstatus(); if (!status.issuccess()) { // toast.maketext(getcontext(), "error contacting api: " + status.tostring(),toast.length_short).show(); log.d("error getting autocomplete prediction api call: ", status.tostring()); autocompletepredictions.release(); return null; } log.d("query completed. received ", string.valueof(autocompletepredictions.getcount())); // freeze results immutable representation can stored safely. return databufferutils.freezeandclose(autocompletepredictions); } log.d(tag, "google api client not connected autocomplete query."); return null; } }
i found solution of nearby places through https://maps.googleapis.com/maps/api/place/nearbysearch/json?. not want!!! want implement facebook checkin functionality in app.
Comments
Post a Comment