title: Calculating distance between two points (Latitude, Longitude)
body: <p>I am trying to calculate the distance between two positions on a map.
  I have stored in my data: Longitude, Latitude, X POS, Y POS.</p>
  
  <p>I have been previously using the below snippet.</p>
  
  <pre><code>DECLARE @orig_lat DECIMAL
  DECLARE @orig_lng DECIMAL
  SET @orig_lat=53.381538 set @orig_lng=-1.463526
  SELECT *,
      3956 * 2 * ASIN(
            SQRT( POWER(SIN((@orig_lat - abs(dest.Latitude)) * pi()/180 / 2), 2) 
                + COS(@orig_lng * pi()/180 ) * COS(abs(dest.Latitude) * pi()/180)  
                * POWER(SIN((@orig_lng - dest.Longitude) * pi()/180 / 2), 2) )) 
            AS distance
  --INTO #includeDistances
  FROM #orig dest
  </code></pre>
  
  <p>I don't however trust the data coming out of this, it seems to be giving slightly inaccurate results.</p>
  
  <p>Some sample data in case you need it </p>
  
  <pre><code>Latitude        Longitude     Distance 
  53.429108       -2.500953     85.2981833133896
  </code></pre>
  
  <p>Could anybody help me out with my code, I don't mind if you want to fix what I already have if you have a new way of achieving this that would be great.</p>
  
  <p>Please state what unit of measurement your results are in.</p>