Android simple way to get latitude and longitude _android

Source: Internet
Author: User
Tags sqlite database stub

The examples in this article describe how Android simply acquires latitude and longitude. Share to everyone for your reference, specific as follows:

public void Getloc () {//position Locationmanager Locationmanager;
     Locationlistener Locationlistener;
     Location Location;
     String contextservice = Context.location_service;
     String provider;
     Double lat;
     Double lon;
     Locationmanager = (Locationmanager) getsystemservice (Contextservice);
     Criteria criteria = new criteria (); Criteria.setaccuracy (criteria.accuracy_fine);//High precision criteria.setaltituderequired (false);/No elevation Criteria.setbea Ringrequired (false);//does not require azimuth criteria.setcostallowed (true);//Allow cost criteria.setpowerrequirement (criteria.power_
     /low power//low-power//from the available location provider, the best provider Provider = Locationmanager.getbestprovider (criteria, true) that matches the above criteria;
     Get the position of the last change location = Locationmanager.getlastknownlocation (provider); Locationlistener = new Locationlistener () {public void onstatuschanged (String provider, int status, Bundle extr AS) {//TODO auto-generated method stub} public VoiD onproviderenabled (String provider) {//TODO auto-generated method stub} public void Onproviderdisabled (
     String provider) {//TODO auto-generated method stub} public void Onlocationchanged (Location Location) {
     lat = Location.getlatitude ();
     lon = Location.getlongitude ();
     LOG.E ("Android_lat", string.valueof (LAT));
     LOG.E ("Android_lon", String.valueof (Lon));
     }
     };
Monitoring position changes, 2 seconds, distance of more than 10 meters locationmanager.requestlocationupdates (provider,,,, Locationlistener);

 }

More interested readers of Android-related content can view the site: Android Development Primer and Advanced tutorials, the Android View View tips Summary, the activity tips summary of Android programming, Android Operation SQLite Database skills Summary, "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card operation method Summary", " Android Resource Operation tips Summary and the "Android Controls usage Summary"

I hope this article will help you with the Android program.

Related Article

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.