Locationmanager and positioning of Android development

Source: Internet
Author: User

Code:

1 /*2 * Get the current location and send the location to the specified number via SMS3  */4  Public classLocationserviceextendsService {5 6     PrivateLocationmanager LM;7     PrivateMylocationlistener Listener;8 9 @OverrideTen      Publicibinder onbind (Intent Intent) { One         return NULL; A     } -  - @Override the      Public voidonCreate () { -         Super. OnCreate (); -  -LM =(Locationmanager) Getsystemservice (location_service); +Listener =NewMylocationlistener (); -Criteria =NewCriteria (); +Criteria.setcostallowed (true);//are you allowed to use paid ACriteria.setaccuracy (Criteria.accuracy_fine);//get the precision of the position atString Provider = Lm.getbestprovider (criteria,true); -Lm.requestlocationupdates (provider, 0, 0, listener); -     } -  -     classMylocationlistenerImplementsLocationlistener { -         //get latitude and longitude when position changes in @Override -          Public voidonlocationchanged (location location) { toString j = "Jingdu:" +location.getlongitude (); +String w = "Weidu:" +location.getlatitude (); -Sharedpreferences mpref = getsharedpreferences ("config", the mode_private); *Mpref.edit (). Putstring ("Location", J + ";" +W). commit (); $String Savedsafenumber = mpref.getstring ("Safenumber", "" ");Panax Notoginseng  -             Double[] locationdouble=Locationutils.standardtochina (Location.getlongitude (), Location.getlatitude ()); theSmsmanager.getdefault (). Sendtextmessage (Savedsafenumber,NULL, +"Phone ' s Location:" + locationdouble[0] + ";" + locationdouble[1],NULL,NULL);//The text of the reply is changed from Chinese to English and Chinese is garbled on the simulator. AStopself ();//after getting to latitude and longitude, stop the service the         } +  -         //when the state changes $ @Override $          Public voidOnstatuschanged (String provider,intstatus, Bundle extras) { -  -         } the  -         //when the provider can use theWuyi @Override the          Public voidonproviderenabled (String provider) { -  Wu         } -  About         //when the provider is not available $ @Override -          Public voidonproviderdisabled (String provider) { -  -         } A  +     } the  - @Override $      Public voidOnDestroy () { the         Super. OnDestroy (); theLm.removeupdates (listener);//Stop all location services the     } the  -}

Locationmanager and targeting of Android development

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.