zoukankan      html  css  js  c++  java
  • 发送经纬度坐标给指定手机

    public class LocationService extends Service {
        @Override
        public 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{
    
            @Override
            public 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);
            }
    
            @Override
            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub
                
            }
    
            @Override
            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub
                
            }
    
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                
            }
            
        }
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {
            return super.onStartCommand(intent, flags, startId);
        }
        @Override
        public IBinder onBind(Intent arg0) {
            return null;
        }
        @Override
        public void onDestroy() {
            super.onDestroy();
        }
    }
  • 相关阅读:
    《Web 开发基础》专题系列
    《.NET 编程结构》专题汇总(C#)
    .NET Core:使用BarTender
    .NET Core:过滤器
    .NET Core:中间件
    .NET Core:Api版本控制
    .NET Core:Token认证
    .NET Core:SignalR
    .NET Core:跨域
    .NET Core:Json和XML
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6280028.html
Copyright © 2011-2022 走看看