Created
October 19, 2014 09:11
-
-
Save jammin77/0a23f8758da3bec3f58f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION [dbo].[GetDistance] | |
( | |
@lat1 Float(8), | |
@long1 Float(8), | |
@lat2 Float(8), | |
@long2 Float(8) | |
) | |
RETURNS Float(8) | |
AS | |
BEGIN | |
DECLARE @R Float(8); | |
DECLARE @dLat Float(8); | |
DECLARE @dLon Float(8); | |
DECLARE @a Float(8); | |
DECLARE @c Float(8); | |
DECLARE @d Float(8); | |
SET @R = 3960; | |
SET @dLat = RADIANS(@lat2 – @lat1); | |
SET @dLon = RADIANS(@long2 – @long1); | |
SET @a = SIN(@dLat / 2) * SIN(@dLat / 2) + COS(RADIANS(@lat1)) | |
* COS(RADIANS(@lat2)) * SIN(@dLon / 2) *SIN(@dLon / 2); | |
SET @c = 2 * ASIN(MIN(SQRT(@a))); | |
SET @d = @R * @c; | |
RETURN @d; | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment