java - How do I output the location using gps on Android -


i trying output location textview. have used locationmanager.tostring(), give me output android.location.locationmanager@44ee7718. output location los angeles, ca 90501.

the code locationmanager:

locationmanager lm = (locationmanager) this.getsystemservice(context.location_service);     //conversion     criteria criteria = new criteria();     string bp = lm.getbestprovider(criteria, false);     location location = lm.getlastknownlocation(bp);     double lat = location.getlatitude();     double lon = location.getlongitude();     geocoder gc = new geocoder(this, locale.getdefault());     list<address> addresses = null;         try{             addresses = gc.getfromlocation(lat, lon, 1);         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }     address address = addresses.get(0);     final string ad = address.getaddressline(0);     //ends here 

the code button:

red.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             // todo auto-generated method stub             intent intent = new intent (intent.action_view);             intent.putextra("sms_body", ad);             intent.settype("vnd.android-dir/mms-sms");             startactivity(intent);         }     }); 

try following code

try {                 // location manager     locationmanager = (locationmanager) getsystemservice(location_service);                     criteria criteria = new criteria();                     bestprovider = locationmanager.getbestprovider(criteria, false);                     location location = locationmanager                             .getlastknownlocation(bestprovider);                     double lat = location.getlatitude();                     double lon = location.getlongitude();                     geocoder gc = new geocoder(this);                     list<address> lstadd = gc.getfromlocation(lat, lon, 1);                     address ad = lstadd.get(0);                     string str = ad.getaddressline(0);                 toast tst = toast.maketext(this, "your current location " + str,                         toast.length_long);                 tst.show(); } catch (exception e) {                 toast tst = toast.maketext(this,"please check gps settings",                         toast.length_long);                 tst.show(); } 

hope helps.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -