Android: ¿cómo encontrar la distancia total cubierta con GPS cuando se mueve continuamente?

Este es mi código. Por favor, dígame y no es capaz de calcular la distancia. En este códigores es una variable larga que se supone que almacena la distancia total cubierta. Se supone que este código calcula la distancia en función del GPS tan pronto como haya un cambio en la latitud y longitud.

String serviceString = Context.LOCATION_SERVICE;
LocationManager locationManager;
locationManager= (LocationManager)getSystemService(serviceString);

String provider = LocationManager.GPS_PROVIDER;
final Location loc1=locationManager.getLastKnownLocation(provider);
//Location loc1=new Location("");

String netprovider=LocationManager.NETWORK_PROVIDER;

lat1=loc1.getLatitude();
lon1=loc1.getLongitude();               

LocationListener myLocationListener = new LocationListener() 
                        {
                            public void onLocationChanged(Location loc1) 
                            {

                            Location loc2=new Location("");
                            lat2=loc2.getLatitude();
                            lon2=loc2.getLongitude();
                            dtvalue.setText(lat1+","+lon1+","+lat2+","+lon2);

                            Location.distanceBetween(lat1,lon1,lat2,lon2,dist);
                            res=res+(long)dist[0];

                            lat1=lat2;
                            lon1=lon2;
                        }
                        public void onProviderDisabled(String provider)
                        {
                            // Update application if provider disabled.
                        }
                        public void onProviderEnabled(String provider)
                        {
                            // Update application if provider enabled.
                        }
                        public void onStatusChanged(String provider, int status,
                                Bundle extras)
                        {
                            // Update application if provider hardware status changed.
                        }
                    };
locationManager.requestLocationUpdates(provider, 5000, 1, myLocationListener);
locationManager.requestLocationUpdates(netprovider, 5000, 1, myLocationListener);