java - Reverse Geocoding Implementation -


i looking implement reverse geocoding in android having problems give me directions? here code:

@override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          textlong = (textview) findviewbyid(r.id.textlong);         textlat = (textview) findviewbyid(r.id.textlat);           locationmanager manager = (locationmanager) getsystemservice(context.location_service);         locationlistener listener = new mylocationlistner();         manager.requestlocationupdates(locationmanager.gps_provider, 0, 0, listener);         }      public class mylocationlistner implements locationlistener{          @override         public void onlocationchanged(location location) {             if (location != null){                  double gettextlong = location.getlongitude();                 double gettextlat = location.getlatitude();                  textlat.settext(double.tostring(gettextlat));                 textlong.settext(double.tostring(gettextlong));               } 

you need create geocoder object , use .getfromlocation method:

geocoder geocoder = new geocoder(this, locale.getdefault()); list<address> addresses = geocoder.getfromlocation(gettextlat, gettextlong, 1); 

i.e.:

public class mylocationlistner implements locationlistener{      geocoder mgeocoder;      // default constructor     mylocationlistener() {         // instantiate geocoder object:         mgeocoder = new geocoder(this, locale.getdefault());     }      @override     public void onlocationchanged(location location) {         if (location != null){              double gettextlong = location.getlongitude();             double gettextlat = location.getlatitude();              textlat.settext(double.tostring(gettextlat));             textlong.settext(double.tostring(gettextlong));              list<address> addresses = mgeocoder.getfromlocation(gettextlat, gettextlong, 1);          }    } 

see: http://developer.android.com/reference/android/location/geocoder.html


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -