2011-12-27 5 views
0

GPS 로거 작업에 도움이 필요합니다. 토글 버튼이 있습니다. 내가 GPS 로거를 시작해야하고 로거 간격을 설정해야합니다. sqlite DB에 위도와 경도를 표시하고 로그 간격에 따라 DB를 업데이트해야합니다.안드로이드 GPS 로거

작동하는 샘플 코드가 도움이 될 것입니다. 나는 많은 샘플 애플리케이션을 발견했다. 그러나 일하지 않았다. 샘플 작업 링크는 큰 도움이 될 것입니다.

답변

2
public class LocalisationService extends Service 
{ 
    private LocationManager locationManager; 
    private BroadcastReceiver receiver; 

    //Define a listener that responds to location updates 
    private LocationListener locationListener = new LocationListener() 
    { 
     //Called when a new location is found by the network location provider 
     public void onLocationChanged(Location location) 
     { 
      //insertion of the location in the DB 
     } 

     public void onStatusChanged(String provider, int status, Bundle extras) {} 

     public void onProviderEnabled(String provider) {} 

     public void onProviderDisabled(String provider) {} 
    }; 

    @Override 
    public IBinder onBind(Intent intent){return null;} 

    @Override 
    public void onCreate() 
    { 
     super.onCreate(); 
     int interval = 1; //Specify the update interval 

     locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 

     // Register the listener with the Location Manager to receive location updates 
     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, locationListener); 

     IntentFilter filter = new IntentFilter(); 
     filter.addAction("STOP_LOCALISATION_SERVICE"); 

     receiver = new BroadcastReceiver() 
     { 
      @Override 
      public void onReceive(Context context, Intent intent) 
      { 
       stopSelf(); 
      } 
     }; 
     registerReceiver(receiver, filter); 
    } 

    @Override 
    public void onDestroy() 
    { 
     unregisterReceiver(receiver); 
     locationManager.removeUpdates(locationListener); 
     super.onDestroy(); 
    } 
} 
관련 문제