0
백그라운드 서비스를 사용하여 1 분마다 또는 1km마다 변경하려는 현재 위치를 원합니다. 그래서 나는이 서비스를 호출 할 때, 내가 한 번만 위치를 얻고, 이제 서비스와 백그라운드 서비스를 사용하여 1 분마다 또는 1km마다 변경 현재 위치를 얻으십시오.
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
is` 서비스의 ONSTART() 메소드 안에 내 코드를 작성했습니다. 문제가 무엇입니까? 이 문제를 해결할 수 있도록 도와주세요.