Forward Geocoding example Code for android? -
has developed code converting address lat/long value. getting confused geocoder. of great if can sample code, using below code. gives error no address found
. not crashes
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mymap = (mapview) findviewbyid(r.id.simplegm_map); // map xml btnsearch = (button) findviewbyid(r.id.simplegm_btn_search); // button xml adress = (edittext) findviewbyid(r.id.simplegm_adress); // address xml gc = new geocoder(this); // create new geocoder instance btnsearch.setonclicklistener(new onclicklistener() { public void onclick(view v) { pd = progressdialog.show(simplegooglemaps.this, "working..", "searching address", true, false); //show progress dialog //thread thread = new thread(simplegooglemaps.this); //then create new thread // thread.start(); //and start thread. automatically call standard run-function. searchadress = new thread() { public void run(){ string addressinput = adress.gettext().tostring(); // input text try { foundadresses = gc.getfromlocationname(addressinput, 5); // search addresses thread.sleep(1500); } catch (exception e) { // @todo: show error message } showadressresults.sendemptymessage(0); } }; searchadress.start(); } }); } private handler showadressresults = new handler() { @override public void handlemessage(message msg) { pd.dismiss(); if (foundadresses.size() == 0) { // if no address found, // display error dialog locationerror = new alertdialog.builder( simplegooglemaps.this).seticon(0).settitle( "error").setpositivebutton(r.string.ok, null) .setmessage( "sorry, address doesn't exist.") .create(); locationerror.show(); } else { // else display address on map (int = 0; < foundadresses.size(); ++i) { // save results longitude , latitude // @todo: if more 1 result, show // select-list address x = foundadresses.get(i); lat = x.getlatitude(); lon = x.getlongitude(); } navigatetolocation((lat * 1000000), (lon * 1000000),mymap); // display found address } } }; /** * navigates given mapview specified longitude , latitude * * @param latitude * @param longitude * @param mv */ public static void navigatetolocation(double latitude, double longitude, mapview mv) { geopoint p = new geopoint((int) latitude, (int) longitude); // new // geopoint mv.displayzoomcontrols(true); // display zoom (seems doesn't // work yet) mapcontroller mc = mv.getcontroller(); mc.animateto(p); // move map given point int zoomlevel = mv.getmaxzoomlevel(); // detect maximum zoom level mc.setzoom(zoomlevel - 1); // zoom mv.setsatellite(false); // display "normal" mapview } }
may below link useful get lat , lon according address
Comments
Post a Comment