I use algorithm (see: calculating distance between two points) to calculate distance between two points. but it get wrong result, see Java code:
/**
* group1:set latitude to 89
*/
// set longitude1 = 0, longitude2 = 1
System.out.println(distance(89, 89, 0, 1, 0 , 0)); // 1941.0 result1
// set longitude1 = 0, longitude2 = 2
System.out.println(distance(89, 89, 0, 2, 0 , 0)); // 3881.0 result2
// set longitude1 = 0, longitude2 = 179
System.out.println(distance(89, 89, 0, 179, 0 , 0)); // 222381.0 result3
// set longitude1 = 0, longitude2 = 180
System.out.println(distance(89, 89, 0, 180, 0 , 0)); // 222390.0 result4
/**
* group2:set latitude to 0
*/
// set longitude1 = 0, longitude2 = 1
System.out.println(distance(0, 0, 0, 1, 0 , 0)); // 111195.0 result5
// set longitude1 = 0, longitude2 = 2
System.out.println(distance(0, 0, 0, 2, 0 , 0)); // 222390.0 result6
// set longitude1 = 0, longitude2 = 179
System.out.println(distance(0, 0, 0, 179, 0 , 0)); // 19903892 result7
// set longitude1 = 0, longitude2 = 180
System.out.println(distance(0, 0, 0, 180, 0 , 0)); // 20015087 result8
In group1:
a = result2 - result1 = 1940
b = result4 - result3 = 9
In group2:
c = result6 - result5 = 111195
d = result8 - result7 = 111195
It's very strange. c = d
, group2 is right, but a ≠ b
, group1 is wrong.
How do I solve this issue?
Is there other higher accuracy algorithm for calculate distance between two coordinate points?