Question: 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.

I've written this code:

```
public void onLocationChanged(Location location) { 
    if(location != null) { 
        if(location.hasSpeed()){ 
            if(latitude1 == 0 && 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"); 
        } 
    } 
}

```

Is it accurated?

Answer: 
Just a Suggestion:

* Store the Latitude and Longitude of the start location and the end location when the user clicks the appropriate button.
* and then you could use [distanceBetween](http://developer.android.com/reference/android/location/Location.html#distanceBetween%28double,%20double,%20double,%20double,%20float%5B%5D%29) or [distanceTo](http://developer.android.com/reference/android/location/Location.html#distanceTo%28android.location.Location%29) to get the distance between those two geoPoints.

P.S: This may not work if the user will start and end his run at the same point ;)

**Addition:**

Check this [tutorial](http://iamvijayakumar.blogspot.in/2012/03/androidcalculate-distance-between-two.html):
Recently google has improved its location based API's. They have fused the sensors with the location based api's to share examples of how location can be made more accurate (about 4 times more effective) and consume much lesser power (10 times lesser).

Some interesting links for you to go through will be [this](http://blogs.esri.com/esri/arcgis/2013/05/15/heres-why-were-excited-about-the-new-google-location-apis/) and [video google io](http://www.youtube.com/watch?v=Bte_GHuxUGc&list=WLRNCZT9Eq_HTG5jIEFxMpdqoXZBNalekx).

SO link for how to use the API's [here](https://stackoverflow.com/questions/16807986/gps-locations-are-not-retrieved-properly/16811119#16811119)