Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Calculate Earth global distances

By Neil Jacobson,

I wrote this sp to be able to calculate the distance between two locations on the earth if the latitude and longitude is known for each.  Could be useful for GPS work or maps.

Usage:
If I know the following city locations:
Sydney         151.2 E             33.87 S
Canberra       149.15 E             35.24 S

DECLARE @RC int
DECLARE @Dist decimal(28,20)
EXEC @RC = [dbo].[sp_EarthDistance] 149.15, -35.24, 151.2, -33.87, @Dist OUTPUT
Select @RC, 'Distance from Sydney and Canberra = ', @Dist

Result (kilometers):
0           Distance between Sydney and Canberra =  242.04260703665335000000

You can change the precision or distance units yourself.

Total article views: 724 | Views in the last 30 days: 5
 
Related Articles
BLOG

Sydney SQL Server Users Group Draws Big Crowd

On Tuesday, October 13, I spoke at the Sydney SQL Server Users Group, presenting on “How to Get th...

SCRIPT

Calculate Distance Between Two Points

This function can be use to calculate distance between two points.

SCRIPT

Calculate distance between 2 coordinates/latlong

This function is used to get the distance between 2 coordinates/latlong in the different formats

ARTICLE

TSQL Challenge 34-Search for two keywords within the maximum distance

This challenge is all about searching for two keywords in a string with a maximum distance of 'one w...

SCRIPT

Calculate Distance in Miles from Latitude and Longitude

A fast and accurate way to calculate the distance in miles between two points, based on the latitude...

Tags
miscellaneous    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones