i get two locations using this :
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
then i compute the distance between them , but the distance is not true
public static float calculateDistance(double e, double f, double g, double h)
{
float dLat = (float) Math.toRadians(g - e);
float dLon = (float) Math.toRadians(h - f);
float a =
(float) (Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(e))
* Math.cos(Math.toRadians(g)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
float c = (float) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
float d = 6371 * c;
return d;
}
(32.2163799,35.0420986) (31.9210915,35.2037014)
the result 36.193707 km but the actual is more than that , approximately 85 km
You can use standart function for this:
More info:http://developer.android.com/reference/android/location/Location.html#distanceTo%28android.location.Location%29
Or distance between function: http://developer.android.com/reference/android/location/Location.html#distanceBetween%28double,%20double,%20double,%20double,%20float[]%29
Use static method distanceBetween() to get distance in meters
Note that the results array packs together several values relating to the distance between the two points: