Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Calculate Distance in Miles from Latitude and Longitude Expand / Collapse
Author
Message
Posted Friday, February 6, 2009 7:32 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, December 4, 2014 7:52 AM
Points: 9,294, Visits: 9,495
Comments posted to this topic are about the item Calculate Distance in Miles from Latitude and Longitude

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #651657
Posted Tuesday, February 17, 2009 1:16 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, December 12, 2014 2:36 AM
Points: 252, Visits: 669
Please could you supply us a "km version" of this nice script.
In Europe, Australia, Asia, etc. we don't use miles or feet. ;)



Post #658276
Posted Tuesday, February 17, 2009 2:52 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 2:03 AM
Points: 44, Visits: 874
Really neat and just what I was looking for.

Many thanks
Tim



Tim
Post #658315
Posted Tuesday, February 17, 2009 6:21 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 8, 2014 6:44 AM
Points: 1,332, Visits: 19,320
RBarryYoung, am I missing something here? the function name is LatLonDistance(), but the tests use calculateDistance()?

Is there a missing piece to this, or is it just a naming convention typo?

Thanks,

Jon


---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
Post #658425
Posted Tuesday, February 17, 2009 7:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 15, 2011 2:01 PM
Points: 2, Visits: 19
Because the earth is not strictly spherical (it "flattens" a bit due to its rotation), there's a mathematical adjustment that can be made which makes the result even more accurate, given any two locations worldwide.

(I researched this about a year ago for a web application involving searching for points of interest within a specified radius of a reference point. I found various algorithms and chose one, which I translated to VBScript. It's nice to see the SQL implementation.)
Post #658477
Posted Tuesday, February 17, 2009 7:17 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 8, 2014 6:44 AM
Points: 1,332, Visits: 19,320
kevin (2/17/2009)
Because the earth is not strictly spherical (it "flattens" a bit due to its rotation), there's a mathematical adjustment that can be made which makes the result even more accurate, given any two locations worldwide.

(I researched this about a year ago for a web application involving searching for points of interest within a specified radius of a reference point. I found various algorithms and chose one, which I translated to VBScript. It's nice to see the SQL implementation.)


And that adjustment is?


---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
Post #658480
Posted Tuesday, February 17, 2009 7:19 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, February 15, 2012 6:37 AM
Points: 9, Visits: 31
As you are using Lat/Long and I do not see any conversion, I am assuming that the distance is measured in Nautical Miles not Statute Miles is it not?
Post #658483
Posted Tuesday, February 17, 2009 7:27 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, November 27, 2014 4:23 AM
Points: 20,584, Visits: 9,624
Henk Schreij (2/17/2009)
Please could you supply us a "km version" of this nice script.
In Europe, Australia, Asia, etc. we don't use miles or feet. ;)


Just do Result time 1.6. Easy enough to include in the function :D.
Post #658492
Posted Tuesday, February 17, 2009 7:43 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, December 12, 2014 2:36 AM
Points: 252, Visits: 669
Quote: "Just do Result time 1.6. Easy enough to include in the function."

I was hoping for new constants in the formula ;)
But I realize the formula doesn't need a 6 or more numbers precision.



Post #658514
Posted Tuesday, February 17, 2009 7:48 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, November 27, 2014 4:23 AM
Points: 20,584, Visits: 9,624
I'm sure it's possible... but to avoid redoing 1 year of maths or waiting for someone to redo the calculations for that constant, I'll just take the small perf hit and do result * 1.6 .
Post #658522
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse