I am calculating the Distance between two Latitudes and Longitudes. I get the results for some distances but sometimes,I get the results as NAN.
This is the Latitude and Longitude which I have got for 2 places.
For eg: 38.655553,-121.091611
38.654875,-121.091324
I am using the below code to calculate the distance with reference to the below link
Calculating distance between two geographic locations
public static double distanceBetween (double currentLat2, double currentLong2, double mallLat2, double mallLong2)
{
float pk = (float) (180/3.14169);
double a1 = currentLat2 / pk;
double a2 = currentLong2 / pk;
double b1 = mallLat2 / pk;
double b2 = mallLong2 / pk;
double t1 = FloatMath.cos((float) a1)*FloatMath.cos((float) a2)*FloatMath.cos((float) b1)*FloatMath.cos((float) b2);
double t2 = FloatMath.cos((float) a1)*FloatMath.sin((float) a2)*FloatMath.cos((float) b1)*FloatMath.sin((float) b2);
double t3 = FloatMath.sin((float) a1)*FloatMath.sin((float) b1);
double tt = Math.acos(t1 + t2 + t3);
return 6366000*tt;
}
Any Help?
Thanks.