title: Calculate distance of two geo points in km c#
body: <p>I`d like calculate the distance of two geo points. the points are given in longitude and latitude.</p>
  
  <p>the coordinates are:</p>
  
  <p>point 1: 36.578581, -118.291994</p>
  
  <p>point 2: 36.23998, -116.83171</p>
  
  <p>here a website to compare the results:</p>
  
  <p><a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="noreferrer">http://www.movable-type.co.uk/scripts/latlong.html</a></p>
  
  <p>here the code I used from this link:
  <a href="https://stackoverflow.com/questions/1502590/calculate-distance-between-two-points-in-google-maps-v3">Calculate distance between two points in google maps V3</a></p>
  
  <pre><code>    const double PIx = Math.PI;
      const double RADIO = 6378.16;
  
      /// &lt;summary&gt;
      /// Convert degrees to Radians
      /// &lt;/summary&gt;
      /// &lt;param name="x"&gt;Degrees&lt;/param&gt;
      /// &lt;returns&gt;The equivalent in radians&lt;/returns&gt;
      public static double Radians(double x)
      {
          return x * PIx / 180;
      }
  
      /// &lt;summary&gt;
      /// Calculate the distance between two places.
      /// &lt;/summary&gt;
      /// &lt;param name="lon1"&gt;&lt;/param&gt;
      /// &lt;param name="lat1"&gt;&lt;/param&gt;
      /// &lt;param name="lon2"&gt;&lt;/param&gt;
      /// &lt;param name="lat2"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static double DistanceBetweenPlaces(double lon1, double lat1, double lon2, double lat2)
      {
          double R = 6371; // km
          double dLat = Radians(lat2 - lat1);
          double dLon = Radians(lon2 - lon1);
          lat1 = Radians(lat1);
          lat2 = Radians(lat2);
  
          double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
          double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
          double d = R * c;
  
          return d;
      }
  
  
  Console.WriteLine(DistanceAlgorithm.DistanceBetweenPlaces(36.578581, -118.291994, 36.23998, -116.83171));
  </code></pre>
  
  <p>the issue is that I get two different results.</p>
  
  <p>my result: 163,307 km</p>
  
  <p>result of the website: 136 km</p>
  
  <p>any suggestions???</p>
  
  <p>torti</p>