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