java - I am trying to get physical address using latitude and longitude in Android -


i trying physical address using latitude , longitude in android

everything working fine coordinates (like one: 32.696627 , 74.8798822) not work , app crashes.

here's code:

import java.util.list; import java.util.locale; import static infolabs.localite.r.id.longitude; public class mainactivity extends appcompatactivity {      string s ="";     edittext lati , longi;     textview t;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);       public void show_me_the_details(view v) throws exception     {          lati  =(edittext)findviewbyid(r.id.latitude);         longi  =(edittext)findviewbyid(r.id.longitude);          double  = double.parsedouble(lati.gettext().tostring());         double b  = double.parsedouble(longi.gettext().tostring());           geocoder geocoder;         list<address> addresses;         geocoder = new geocoder(this, locale.getdefault());           addresses = geocoder.getfromlocation(a, b, 1); // here 1 represent max location result returned, documents recommended 1 5          string address = addresses.get(0).getaddressline(0); // if additional address line present only, check max available address lines getmaxaddresslineindex()         string city = addresses.get(0).getlocality();         string state = addresses.get(0).getadminarea();         string country = addresses.get(0).getcountryname();         string postalcode = addresses.get(0).getpostalcode();         string knownname = addresses.get(0).getfeaturename();          textview t = (textview)findviewbyid(r.id.details);          string full_address = address+"\n"+city+"\n"+state+"\n"+country+"\n"+postalcode+"\n"+knownname+"\n";         t.settext(full_address);      } } 

andriod's geocoder api free , give u correct address.

as per crashing concerned need debug it.try put logging , enclose code in try catch.

observation : have observed geocoder code u wrote in ui thread not way should calculated in background service there cases program hang if api takes lot of time.

try go through andriod standard practice geocoder popular api.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -