I've got a problem with mesuring distance between two locations.

One of them is my location:

Using java Syntax Highlighting

- public void onLocationChanged(Location location)
- {
- ...
- curLocation = location;
- }

Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Second location i want to create myself. To test it i simply went to that place checked what curLocation.getLatitude() and curLocation.getLongitude() will give me. Then i set some coordinates for a new location:

Using java Syntax Highlighting

- double lat2 = 20.9499192237854; // this is number which curLocation.getLatitude() returned when i was there
- double long2 = 52.26164494037628; // this is number which curLocation.getLongitude() returned when i was there
- Location loc2 = new Location("WHAT TO WRITE HERE ?!?!");
- loc2.setLatitude(lat2);
- loc2.setLongitude(long2);

Parsed in 0.031 seconds, using GeSHi 1.0.8.4

I try to count it in many ways like this:

Using java Syntax Highlighting

- float[] distance = new float[2];
- Location.distanceBetween(lat1, long1, lat2, long2, distance);

Parsed in 0.034 seconds, using GeSHi 1.0.8.4

or this:

Using java Syntax Highlighting

- curLocation.distanceTo(loc2);

Parsed in 0.035 seconds, using GeSHi 1.0.8.4

or this:

Using java Syntax Highlighting

- double deltaLat = lat2 - lat1;
- double deltaLong = long2 - long1;
- double a = Math.sin(deltaLat/2)*Math.sin(deltaLat/2) + Math.cos(lat1)*Math.cos(lat2)*Math.sin(deltaLong/2)*Math.sin(deltaLong/2);
- double c = 2*Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
- double d = c * 6371;

Parsed in 0.037 seconds, using GeSHi 1.0.8.4

or this:

Using java Syntax Highlighting

- float pk = (float) (180/3.14169);
- float a1 = lat1 / pk;
- float a2 = long1 / pk;
- float b1 = lat2 / pk;
- float b2 = long2 / pk;
- float t1 = FloatMath.cos(a1)*FloatMath.cos(a2)*FloatMath.cos(b1)*FloatMath.cos(b2);
- float t2 = FloatMath.cos(a1)*FloatMath.sin(a2)*FloatMath.cos(b1)*FloatMath.sin(b2);
- float t3 = FloatMath.sin(a1)*FloatMath.sin(b1);
- double tt = Math.acos(t1 + t2 + t3);

Parsed in 0.037 seconds, using GeSHi 1.0.8.4

All of this algorithms and methods are giving me a bad results - instead of eg.50m or 0,050 km it gives me something like 620, 4040104102 etc.

Can someone help me how to fix it?