Calculate Distance traveled android using location manager : <p>I am currently working on a simple fitness app that allows user to track his/her performance (running,walking). I have been using location manager to get the moving speed which works very fine. However I need to get the distance traveled, how can use location manager (long and lat) to get the distance ?</p>

<p>Thanks</p>

<pre><code>@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_track);

    start = (Button) findViewById(R.id.btnStart);
    speed = (TextView) findViewById(R.id.txtSpeed);
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);


    //initialize location listener
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            getSpeed(location);
            double lat2 = location.getLatitude();
            double lng2 = location.getLongitude();
        }

        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {

        }

        @Override
        public void onProviderEnabled(String s) {

        }

        @Override
        public void onProviderDisabled(String s) {
        }

        //get the speed from the given location updates
        public void getSpeed(Location location) {
            currentSpeed = (location.getSpeed() * 3600 / 1000);
            String convertedSpeed = String.format("%.2f", currentSpeed);
            speed.setText(convertedSpeed + "Km/h");
        }
    };
</code></pre>
