title: Running GPS Values
body: <p>I'm trying to get GPS values every few seconds and I'm missing some trick. Here's what I've tried:</p>
  
  <pre><code>public class Locn extends ActionBarActivity 
  {
      private LocationManager locationManager;
      private String provider;
      private Location loc = null;
      private Criteria criteria;
      ... local variables ...
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          ...
  
          // Get the location manager
          locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
          LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
          boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
  
          // Check if enabled. If not send user to the GPS settings
          if (!enabled) 
          {
              Toast.makeText(this, "Please enable GPS location service",  
                        Toast.LENGTH_SHORT).show();
              Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
              startActivity(intent);
          }
          else 
          {
          Toast.makeText(this, "GPS location service is enabled", 
                        Toast.LENGTH_SHORT).show();
          }
          // Define the criteria to select the location provider -&gt; use default
          criteria = new Criteria();
          criteria.setAccuracy(Criteria.ACCURACY_FINE);
          criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
  
          // Let Android select the best location provider based on criteria
          provider = locationManager.getBestProvider(criteria, true);
  
          ...
      }
  
      //--------------------------------------
      // Set up timer handlers
      Handler timerHandler = new Handler();
      Runnable timerRunnable = new Runnable() 
      {
          @Override
          public void run() 
          {
              provider = locationManager.getBestProvider(criteria, true);
              loc = locationManager.getLastKnownLocation(provider);
  
              milli = System.currentTimeMillis();
          longitude = loc.getLongitude();
          latitude = loc.getLatitude();
          count++;
  
              timerHandler.postDelayed(this, 2000);
          }    
      };
  </code></pre>
  
  <p>count and milli changes every two seconds but the latitude and longitude do not change at all. (Yes, I'm changing position -- up to 2 miles)</p>
  
  <p>What am I missing here?  Does loc have to be cleared before calling getLastKnownLocation again?</p>
  
  <p>Thanks,
  Walt</p>