title: Return distance between two locations in SQL Server 2008 using latitude and longitude
body: <p>We have a table with places and their latitudes and longitudes.</p>
  
  <p>We are trying to create a function in SQL Server 2008 to list places within next 25 kilometers using a specific latitude and longitude as centre point. </p>
  
  <p>I was wandering if this is a good way to start and test our function and getting current distance between a centre point (current location) and a target location (@latitude/@longitude):</p>
  
  <pre><code>ALTER FUNCTION [dbo].[GetDistanceFromLocation]
  (   
      @myCurrentLatitude float,
      @myCurrentLongitude float,
      @latitude float,
      @longitude float
  )
  RETURNS int
  AS
  BEGIN
      DECLARE @radiusOfTheEarth int 
      SET @radiusOfTheEarth = 6371--km
  
      DECLARE @distance int
      SELECT @distance = ( @radiusOfTheEarth 
          * acos( cos( radians(@myCurrentLatitude) ) 
          * cos( radians( @latitude ) ) 
          * cos( radians( @longitude ) - radians(@myCurrentLongitude) ) + sin( radians(@myCurrentLatitude) ) 
          * sin( radians( @latitude ) ) ) )
  
      RETURN @distance
  
  END
  </code></pre>
  
  <p>Is it correct or we are missing something?</p>