发送经纬度坐标给指定手机
生活随笔
收集整理的這篇文章主要介紹了
发送经纬度坐标给指定手机
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public class LocationService extends Service {@Overridepublic void onCreate() {super.onCreate();//獲取手機的經緯度坐標//1,獲取位置管理者對象LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);//2,以最優的方式獲取經緯度坐標()Criteria criteria = new Criteria();//允許花費criteria.setCostAllowed(true);criteria.setAccuracy(Criteria.ACCURACY_FINE);//指定獲取經緯度的精確度String bestProvider = lm.getBestProvider(criteria, true);//3,在一定時間間隔,移動一定距離后獲取經緯度坐標MyLocationListener myLocationListener = new MyLocationListener();lm.requestLocationUpdates(bestProvider, 0, 0, myLocationListener);}class MyLocationListener implements LocationListener{@Overridepublic void onLocationChanged(Location location) {//經度double longitude = location.getLongitude();//緯度double latitude = location.getLatitude();//4,發送短信(添加權限)SmsManager sms = SmsManager.getDefault();sms.sendTextMessage("5556", null, "longitude = "+longitude+",latitude = "+latitude, null, null);}@Overridepublic void onProviderDisabled(String provider) {// TODO Auto-generated method stub
}@Overridepublic void onProviderEnabled(String provider) {// TODO Auto-generated method stub
}@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {}}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {return super.onStartCommand(intent, flags, startId);}@Overridepublic IBinder onBind(Intent arg0) {return null;}@Overridepublic void onDestroy() {super.onDestroy();}
}
?
轉載于:https://www.cnblogs.com/xufengyuan/p/6280028.html
總結
以上是生活随笔為你收集整理的发送经纬度坐标给指定手机的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux界面自动化测试框架不完全汇总
- 下一篇: ThinkPHP批量添加数据和getFi