2012-11-09 2 views
3

현재 위치를 찾고 백그라운드 서비스 활동을 통해 내 데이터베이스의 일부 데이터와 비교하고 싶습니다. 그러나 어떻게하는지에 대한 아이디어는 얻지 못하고 있습니다. 나는이 분야에서 작품의 전체를 많이 않은 현재 일을백그라운드 서비스에서 현재 위치 찾기 android

package com.example.alert; 

    import android.app.Service; 
    import android.content.Context; 
    import android.content.Intent; 
    import android.location.Location; 
    import android.location.LocationListener; 
    import android.location.LocationManager; 
    import android.media.MediaPlayer; 
    import android.os.Bundle; 
    import android.os.IBinder; 
    import android.widget.Toast; 

    public class service extends Service{ 
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

@Override 
public IBinder onBind(Intent arg0) { 
    // TODO Auto-generated method stub 
    return null; 
} 

public void onCreate() { 
    Toast.makeText(this, "Background Service Created", Toast.LENGTH_LONG).show(); 



} 

public void onDestroy() { 
    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); 


} 

public void onStart(Intent intent, int startid) { 

    Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); 
    LocationListener ll = new MyLocationListener(); 
    //lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*60*10000, 0, ll); 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); 



} 


public class MyLocationListener implements LocationListener 
{ 

    public void onLocationChanged(Location loc) 
    { 
     if(loc!=null) 
     { 
      double x; 


      String Text = "My current location is: " +"Latitud = " + loc.getLatitude() +"Longitud = " + loc.getLongitude(); 
      Toast.makeText(getApplicationContext(),Text,Toast.LENGTH_SHORT).show(); 
     /* cr.moveToFirst(); 
      while(!cr.isAfterLast()) { 
       al.add(cr.getString(cr.getColumnIndex(dbAdapter.KEY_NAME))); //add the item 
       cr.moveToNext(); 
      }*/ 
     // lm.addProximityAlert(loc.getLatitude(), loc.getLongitude(), 10009,, intent) 

      //for loop, alerters retrieving one by one 
//  x= calcDistance(loc.getLatitude(),loc.getLongitude(),z,y); 
    //  if(x<1){ 
     //  Intent myIntent = new Intent(ViewAlerters.this,CallMode.class); 
      //  startActivity(myIntent); 
      } 

     } 



    public void onProviderDisabled(String arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onProviderEnabled(String provider) { 
     // TODO Auto-generated method stub 

    } 

    public void onStatusChanged(String provider, int status, Bundle extras) { 
     // TODO Auto-generated method stub 

    } 


    } 
    } 
+0

체크 아웃 내가 [여기]를 묻는 질문에 샘의 대답 (http://stackoverflow.com/questions/12983431/not-receiving-location-data -from-thread). 너를 도울거야. – chRyNaN

답변

관련 문제