Android get latitude and longitude

Source: Internet
Author: User

Package Com.potergps.findlocation;import Java.util.list;import Com.poter.findlocation.r;import Android.location.location;import Android.location.locationlistener;import Android.location.LocationManager; Import Android.os.bundle;import android.app.activity;import Android.util.log;import Android.view.menu;import    Android.widget.textview;public class Mainactivity extends Activity {private Locationmanager lm;//define Private TextView TV;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Lm= (Locationmanager) Getsystemservice (location_service);//Initialize list<string> provider= lm.getAllProviders ();//        Get all the positioning methods for (String Way:provider) {System.out.println (way);        LOG.I ("##############");        }; Listener positioning, first parameter mode, 2, time. 3, distance. 4, monitor lm.requestlocationupdates ("GPs", 0, 0, new Locationlistener () {@Overridepublic void onstatuschanged (String provider, int status, Bundle extras) {//TODO auto-generated method stub} @Overridepublic void Onproviderenabled (String pr Ovider) {//Todo auto-generated method stub} @Overridepublic void Onproviderdisabled (String provider) {//Todo Auto-genera Ted method stub} @Overridepublic void Onlocationchanged (location location) {//TODO auto-generated method stubstring Longi Tude = "J:" + location.getlongitude () + "\ n"; String latitude = "W:" + location.getlatitude () + "\ n"; String accuracy = "a" + location.getaccuracy () + "\ n"; tv= (TextView) Findviewbyid (r.id.tv); Tv.settext ("J:" + Location.get    Longitude () + "\ n" + "W:" + location.getlatitude () + "\ n" + "a" + location.getaccuracy () + "\ n");});    } @Overrideprotected void OnDestroy () {//TODO auto-generated method Stubsuper.ondestroy ();} }

  

Android get latitude and longitude

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.