android - Call Google Place Api on EditText -
i using google place api in app , working perfactly when using fragment want call functionality on click on edittext how call that?
placepicker.intentbuilder builder = new placepicker.intentbuilder(); mgoogleapiclient = new googleapiclient .builder(this) .addapi(places.place_detection_api) .enableautomanage(this, this) .build(); try { startactivityforresult(builder.build(this), place_picker_request); } catch (googleplayservicesrepairableexception | googleplayservicesnotavailableexception e) { e.printstacktrace(); } pendingresult<placelikelihoodbuffer> result = places.placedetectionapi .getcurrentplace(mgoogleapiclient, null); result.setresultcallback(new resultcallback<placelikelihoodbuffer>() { @override public void onresult(placelikelihoodbuffer likelyplaces) { (placelikelihood placelikelihood : likelyplaces) { } likelyplaces.release(); } });
if commenting code placeautocompletefragment before try block,yet working,so not understanding working , how correct that:
placeautocompletefragment autocompletefragment = (placeautocompletefragment) getfragmentmanager().findfragmentbyid(r.id.place_autocomplete_fragment); autocompletefragment.setonplaceselectedlistener(new placeselectionlistener() { @override public void onplaceselected(place place) { // todo: info selected place. // log.i(tag, "place: " + place.getname()); } @override public void onerror(status status) { // todo: handle error. //log.i(tag, "an error occurred: " + status); } }); try { intent intent = new placeautocomplete.intentbuilder(placeautocomplete.mode_fullscreen) .build(this); startactivityforresult(intent, place_autocomplete_request_code); } catch (googleplayservicesrepairableexception | googleplayservicesnotavailableexception e) { // todo: handle error. } }
here calling activityresult :
protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == place_picker_request) { if (resultcode == result_ok) { place place = placepicker.getplace(data, this); string toastmsg = string.format("place: %s", place.getname()); toast.maketext(this, toastmsg, toast.length_long).show(); } } if (requestcode == place_autocomplete_request_code) { if (resultcode == result_ok) { place place = placeautocomplete.getplace(this, data); //log.i(tag, "place: " + place.getname()); } else if (resultcode == placeautocomplete.result_error) { status status = placeautocomplete.getstatus(this, data); // todo: handle error. // log.i(tag, status.getstatusmessage()); } else if (resultcode == result_canceled) { // user canceled operation. } } }
Comments
Post a Comment