title: distance always equals to zero
body: <p>I have an app which calculates distance and speed by gps
  the speed is working well
  but the distance always equals to zero !!</p>
  
  <p>at first i didn't initialize float[] dist by zero .. but it crashed once gps was found !</p>
  
  <p>that's the code </p>
  
  <pre><code>public class Main_Activity extends Activity {
  
      TextView tvdistance;
      TextView tvSpeed;
  
      double currentLon = 0;
      double currentLat = 0;
      double lastLon = 0;
      double lastLat = 0;
      double distance = 0;
      float[] dist = {
              0, 0, 0
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_layout);
          tvdistance = (TextView) findViewById(R.id.tvdistance);
          tvSpeed = (TextView) findViewById(R.id.tvspeed1);
  
          LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
          lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, Loclist);
          Location loc2 = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
          if (loc == null) {
              tvdistance.setText("No GPS location found");
          }
          else {
              // set Current latitude and longitude
              currentLon = loc.getLongitude();
              currentLat = loc.getLatitude();
  
          }
          // Set the last latitude and longitude
          lastLat = currentLat;
          lastLon = currentLon;
  
      }
  
      LocationListener Loclist = new LocationListener() {
  
          @Override
          public void onLocationChanged(Location location) {
              // TODO Auto-generated method stub
  
              // start location manager
              LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
  
              // Get last location
              Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
              // Request new location
              lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, Loclist);
  
              // Get new location
              Location loc2 = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
              // get the current lat and long
              currentLat = loc.getLatitude();
              currentLon = loc.getLongitude();
  
              if (currentLat != 0 &amp;&amp; currentLon != 0) {
  
                  Location.distanceBetween(currentLat, currentLon, location.getLatitude(),
                          location.getLongitude(), dist);
                  distance += (long) dist[0];
              }
  
              currentLat = location.getLatitude();
              currentLon = location.getLongitude();
  
              float speed = location.getSpeed();
              tvSpeed.setText("Speed = " + speed / 1000 * 60 * 60 + "Km/h");
              tvdistance.setText("Distance = " + distance);
  
          }
  
          @Override
          public void onProviderDisabled(String provider) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onProviderEnabled(String provider) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
              // TODO Auto-generated method stub
  
          }
  
      };
  
  }
  </code></pre>