Android 使用后台服务,每1分钟或每1公里更改一次当前位置

Android 使用后台服务,每1分钟或每1公里更改一次当前位置,android,service,currentlocation,Android,Service,Currentlocation,我想使用后台服务获得每1分钟或每1公里更改的当前位置。因此,我编写了一个服务,服务的onStart方法中的代码是` if(lm==null) lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); //exceptions will be thrown if provider is not permitted. try{gps_enabled=lm.isPr

我想使用后台服务获得每1分钟或每1公里更改的当前位置。因此,我编写了一个服务,服务的onStart方法中的代码是`

if(lm==null)
 lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

            //exceptions will be thrown if provider is not permitted.
            try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}
            catch(Exception ex){
                Log.d("location","Exception gps enabled....."+ex.toString());
            }
            try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}
            catch(Exception ex){
                Log.d("location","Exception network enabled....."+ex.toString());
            }



            if(gps_enabled){

                lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 6000, 1000,locationListenerGps);
            }
            if(network_enabled)
            {
                Log.d("location","network_enabled.....");
                lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 1000, locationListenerNetwork);

            }


    }
    LocationListener locationListenerGps = new LocationListener() {
        public void onLocationChanged(Location location) {

            lm.removeUpdates(this);
            lm.removeUpdates(locationListenerNetwork);
            Log.d("location","Latitude from gps....."+ location.getLatitude());
            Log.d("location","Longitude from gps....."+location.getLongitude());
        }
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status, Bundle extras) {}
    };

    LocationListener locationListenerNetwork = new LocationListener() {
        public void onLocationChanged(Location location) {

            lm.removeUpdates(this);
            lm.removeUpdates(locationListenerGps);
            Log.d("location","Latitude from network ....."+ location.getLatitude());
            Log.d("location","Longitude from network ....."+location.getLongitude());
        }
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status, Bundle extras) {}
    };code here

现在,当我调用此服务时,我只获得一次位置信息。有什么问题?请帮助我解决此问题

使用计时器并每一分钟运行一次获取当前位置的线程