title: onLocationChange() not getting called? Calculate Distance Travelled -Android
body: <p>I have this code:</p>
  
  <pre><code>Location newLocation = new Location(LocationManager.GPS_PROVIDER);
  Location oldLocation = new Location(LocationManager.GPS_PROVIDER);
  float distanceTravelled=0;
  </code></pre>
  
  <p>onLocationChanged:</p>
  
  <pre><code>@Override
  public void onLocationChanged(Location location) 
  {
      oldLocation.set(newLocation);
      startactivity();
      distanceTravelled+=newLocation.distanceTo(oldLocation);
      String stringDistance= Float.toString(distanceTravelled);
      TextView distance = (TextView) findViewById(R.id.textDistance);
      distance.setText(stringDistance);
  }
  </code></pre>
  
  <p>startactivity:</p>
  
  <pre><code>public void startactivity() 
  {
      GPSTracker gps = new GPSTracker(Live.this);
  
      if(gps.canGetLocation())
      {
          double latitude = gps.getLatitude();
          double longitude = gps.getLongitude();
          Toast.makeText(getApplicationContext(), "Your Location is: \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
  
          newLocation.setLatitude(latitude);
          newLocation.setLongitude(longitude);    
      }
      else
      {
          gps.showSettingsAlert();
      }
  
  }
  </code></pre>
  
  <p>GPSTracker is a separate class which gets the current latitude and longitude (it is working fine!).</p>
  
  <p>GPS updates at min. distance 5 metres and min. time 5 seconds.</p>
  
  <p>Here is my full GPSTracker class: <strong><em><a href="http://pastebin.com/B5TWTNq8" rel="nofollow">GPSTracker.java</a></em></strong></p>
  
  <p>I have added the three permissions in the manifest: fine,coarse and internet.</p>
  
  <p>My problem is the textview inside onLocationChanged never gets changed.</p>
  
  <p>What is the problem? Is onLocationChanged not getting called or there is some logical error (distance always remains zero)?</p>
  
  <p>And how to fix that?</p>