Calculating distance between 2 points

  • Hi all,

    I need the formula for calculating the distance between 2 points.

    Data we have is

    Point - Latitude, Longitude, Latitude Declination, Longitude Declination

    and appears as

    Lat: 51° 39' North

    Long: 121° 17' West

    LatDec: 51.649999999999999

    Long Dec: -121.2833

    Thanks in advance,

    Paul

  • You can try to convert your Declinations into a 2nd set of Latitude, Longitude, then use:

    CREATE FUNCTION dbo.fn_GreatCircleDistance

     (@Latitude1 float = NULL,

     @Longitude1 float = NULL,

     @Latitude2 float = NULL,

     @Longitude2 float = NULL)

    RETURNS float

    AS

    BEGIN

     IF @Latitude1 IS NULL RETURN 0

     IF @Longitude1 IS NULL RETURN 0

     IF @Latitude2 IS NULL RETURN 0

     IF @Longitude2 IS NULL RETURN 0

     RETURN (ACOS(SIN(@Latitude1 * PI() / 180) * SIN(@Latitude2 * PI() / 180) +

      COS(@Latitude1 * PI() / 180) * COS(@Latitude2 * PI() / 180) * COS((@Longitude2 - @Longitude1) * PI() / 180)) * 3963.1)

    END

    GO

    Andy

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply