title: android GPS still getting postion when i'm not moving
body: <p>I'm developing a tracking app. and i have problem with GPS module. The app must record a route. App work fine, but sometimes when the device is not moving, GPS still receive 
  continuous coordinate that don't indicate my position, error is within a radius of 20 meter, and when I'm moving again work fine. 
  Please give me some tips that can help me to fix this problem. Thanks a lot.</p>
  
  <p>I have 3 calsses </p>
  
  <p>1 - GPSReceiver here is method for get location</p>
  
  <pre><code>public void getMyLoction(){ 
      _locationManager = (LocationManager) _context.getSystemService(LOCATION_SERVICE);
      _isGPSEnabled    =_locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);     
      if (_isGPSEnabled) {
          if (_location == null) {
              _locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0, this);
              if (_locationManager != null) {                 
                  _location = _locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                  setLocation(_location);
              }
          }
      }
  
  }
  </code></pre>
  
  <p>2 RecordingActivity (take coordonates form services and processes then) work fine, a comment in method what they do.</p>
  
  <pre><code>public class RecordingActivity extends FragmentActivity {
  
  public final static String BROADCAST_ACTION = "map.trackv";
  public BroadcastReceiver receiver;
  
  private GoogleMap map;
  private TextView _messageToUser;
  private Coordinate _pointFromService;
  private long _timeWhenStartButtonWasPressed;
  
  private List&lt;Coordinate&gt; _unprocessedCoords;
  private List&lt;Coordinate&gt; _processedCoords;
  
  private Button _stopButton;
  private Button _startButton;
  
  private String _startRecordingDate;
  private String _stopRecordingDate;
  private GPSReceiver _gps;
  
  private DataBaseOperations _dataSource;
  
  private boolean _recording;
  private boolean _gpsStatus;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_recording_route);
      initActvity();
  
      checkIfGPSisOn();
      try {
          Runtime.getRuntime().exec("logcat -f" + " /sdcard/Logcat.txt");
      } catch (IOException e) {
          // TODO Auto-generated catch block
          Log.d("nu pot", "DDDDD");
          e.printStackTrace();
      }
  
  
  
      receveirWork();
      IntentFilter intentFilt = new IntentFilter(BROADCAST_ACTION);
      registerReceiver(receiver, intentFilt);
  
  }
  
  public void checkIfGPSisOn() {
      //check on start
  }
  
  public void receveirWork() {
  
      receiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
  
              // request points and process then, 
          }
  
      };
  }
  
  
  
  @Override
  protected void onDestroy() {
      super.onDestroy();  
  
      if (_stopButton.isEnabled())
      {
          stopService(new Intent(this, RecordingService.class));
          _unprocessedCoords = null;
          _processedCoords   = null;
      }
      unregisterReceiver(receiver);
  }
  
  @Override
  protected void onResume() {
  
      if (!_stopButton.isEnabled()) {
          _startButton.setEnabled(true);
          _messageToUser.setText(Constants.PRESS_START_BUTTON);
          map.clear();
      }
      super.onResume();
  }
  
  // actiune buton start;
  public void startButtonEvent(View V) {
      buttonsStateAndMessageToShow(false, true, Constants.MESSAGE_TO_WAIT);
      _timeWhenStartButtonWasPressed = System.currentTimeMillis();        
      startService(new Intent(this, RecordingService.class));
  
  // start service to get position
  }
  
  
  
  public void stopButtonEvent(View V) {
      stopService(new Intent(this, RecordingService.class));
      // stop service         
      // save route in BD     
      // resetData;
  }   
  public void initActvity() {
      // init date    
  
  }
  
  @Override
  protected void onSaveInstanceState(Bundle outState) {
      // save state       
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>3 RecordingServices class, ii think here is the problem.</p>
  
  <pre><code>public class RecordingService extends Service {
  
  private Thread _backgroundWork;
  private boolean _threadCanRun;
  private GPSReceiver _gps;
  private Coordinate _pointToSent;
  
  public void onCreate() {
      super.onCreate();
      _threadCanRun = true;
      _backgroundWork = new Thread(new Runnable() {
          @Override
          public void run() {
              Looper.prepare();
              getLocationFromGPS();
              Looper.loop();
  
          }
      });
  
  }
  
  public int onStartCommand(Intent intent, int flags, int startId) {//    
      _backgroundWork.start();
      return super.onStartCommand(intent, flags, startId);
  }
  
  public void onDestroy() {
      _threadCanRun = false;
      super.onDestroy();
  }
  
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  public void getLocationFromGPS() {
  
      while (_threadCanRun) {
          Intent _intent = new Intent(RecordingActivity.BROADCAST_ACTION);
          _gps = new GPSReceiver(this);       
  
          _gps.getMyLoction();
          if (_gps.getIsGPSEnabled()) {
  
          try {
                  TimeUnit.SECONDS.sleep(2);
              } catch (InterruptedException e) {}             
              sentPoint(_intent);
  
          } else {
  
              try {
                  TimeUnit.MILLISECONDS.sleep(500);
              } catch (InterruptedException e) {}
  
              _intent.putExtra("latitude", 0);
              _intent.putExtra("longitude", 0);
              _intent.putExtra("time", 0);
              _intent.putExtra("GPSstatus", false);
              sendBroadcast(_intent);
          }
      }
  }
  
  
  private void sentPoint(Intent _intent) {
      _pointToSent = new Coordinate(_gps.getLatitude(), _gps.getLongitude(),  _gps.getTime());
      _intent.putExtra("latitude", _pointToSent.getLatitude());
      _intent.putExtra("longitude", _pointToSent.getlongitude());
      _intent.putExtra("time", _pointToSent.getTime());
      _intent.putExtra("GPSstatus", _gps.getIsGPSEnabled());
  
      sendBroadcast(_intent);
      _pointToSent = null;
  
  }
  </code></pre>
  
  <p>}</p>