title: Finding current location from background service android
body: <p>I want to find current location and compare it with some data in my database through a background service activity...but not getting any idea on how to do it...so please give me some advice...this is how I am doing currently</p>
  
  <pre><code>    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&lt;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
  
      }
  
  
      }
      }
  </code></pre>