0

So i was trying to duplicate the distance formula on this page in C#.

http://www.movable-type.co.uk/scripts/latlong.html

This is for distance between two coordinates.

This is my code

int R = 6371;
double Lat1 = ((Double.Parse(SLat))*(Math.PI/180));
double Lat2 = ((Double.Parse(SLat2)) * (Math.PI / 180));
double deltaOmega = (Double.Parse(SLat) - Double.Parse(SLat2)) * (Math.PI / 180);
double deltaLambda = (Double.Parse(SLong) - Double.Parse(SLong2)) * (Math.PI / 180);

double a = Math.Sin(deltaOmega / 2) * Math.Sin(deltaOmega / 2) 
    + Math.Cos(Lat1) * Math.Cos(Lat2) 
    * Math.Sin(deltaLambda / 2) * Math.Sin(deltaLambda/ 2);
double c = 2* Math.Atan2(Math.Sqrt(a), Math.Sqrt(1-a));

double dis = R * c;

but i keep getting a distance that is two decimal places off.

Can anyone verify that my translation of the equation is correct?

juharr
  • 31,741
  • 4
  • 58
  • 93
user1775297
  • 87
  • 11
  • Can you show the input, output, and desired output? I don't see any obvious differences between your code that the code in the link. – juharr Nov 03 '14 at 15:31
  • I just tried the values on that link (50.066388888 N, 5.714722222 W) and (58.64388888 N, 3.07 W) with your code and got 968.853. Are you sure you're entering the initial values correctly (converting the minutes and seconds to the decimal places of a degree)? – juharr Nov 03 '14 at 15:48

0 Answers0