title: Android: How can I get the traveled distance while I'm running?
body: <p>I'm wrinting a application and I have to show the distance covered while I'm running.
  I use the function "public void onLocationChanged" of the LocationListener. When the user tap a botton and start running I want to show the distance he covered updated to the point in which he is located.</p>
  
  <p>I've written this code:</p>
  
  <pre><code>public void onLocationChanged(Location location) { 
      if(location != null) { 
          if(location.hasSpeed()){ 
              if(latitude1 == 0 &amp;&amp; longitude1 == 0){
                  latitude1 = (location.getLatitude()*Math.PI)/180;
                  longitude1 = (location.getLongitude()*Math.PI)/180;
              } else{
                  latitude2 = (location.getLatitude()*Math.PI)/180;
                  longitude2 = (location.getLongitude()*Math.PI)/180;
                  distance = (6372.795477598)*Math.acos(Math.sin(latitude1)
                             *Math.sin(latitude2)+Math.cos(latitude1)
                             *Math.cos(latitude2)*Math.cos(longitude1-longitude2));
                  sumDistance += distance;
                  latitude1 = latitude2;
                  longitude1 = longitude2;
              }
  
              tv.setText("Distance covered=" + sumDistance + " m"); 
          } 
      } 
  }
  </code></pre>
  
  <p>Is it accurated?</p>