Send latitude and longitude coordinates to the specified phone

Source: Internet
Author: User

 Public classLocationserviceextendsService {@Override Public voidonCreate () {Super. OnCreate (); //get the latitude and longitude coordinates of your phone//1, get the Location Manager ObjectLocationmanager LM =(Locationmanager) Getsystemservice (Location_service); //2, the best way to obtain the latitude and longitude coordinates ()Criteria =NewCriteria (); //allowed to spendCriteria.setcostallowed (true); Criteria.setaccuracy (criteria.accuracy_fine);//Specify the accuracy of getting latitude and longitudeString Bestprovider = Lm.getbestprovider (criteria,true); //3, at a certain time interval, moving a certain distance after the latitude and longitude coordinatesMylocationlistener Mylocationlistener =NewMylocationlistener (); Lm.requestlocationupdates (Bestprovider,0, 0, Mylocationlistener); }        classMylocationlistenerImplementslocationlistener{@Override Public voidonlocationchanged (location location) {//Longitude            DoubleLongitude =Location.getlongitude (); //Latitude            DoubleLatitude =Location.getlatitude (); //4. Send SMS (add permission)Smsmanager SMS =Smsmanager.getdefault (); Sms.sendtextmessage ("5556",NULL, "longitude =" +longitude+ ", Latitude =" +latitude,NULL,NULL); } @Override Public voidonproviderdisabled (String provider) {//TODO auto-generated Method Stub} @Override Public voidonproviderenabled (String provider) {//TODO auto-generated Method Stub} @Override Public voidOnstatuschanged (String provider,intstatus, Bundle extras) {}} @Override Public intOnstartcommand (Intent Intent,intFlagsintStartid) {        return Super. Onstartcommand (Intent, flags, Startid); } @Override Publicibinder onbind (Intent arg0) {return NULL; } @Override Public voidOnDestroy () {Super. OnDestroy (); }}

Send latitude and longitude coordinates to the specified phone

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.