General information
Forum:
Microsoft SQL Server
Environment versions
SQL Server:
SQL Server 2008
Please note that the output of the distance calculation from my blog is in MILES, not kilometers. You may need to convert it to kilometers for your own use.
I spent a considerable amount of time optimizing this UDF for performance. One thing I realized is that the PI() function is slow. Since PI isn't about to change anytime soon, it is faster to simply use a constant. SQL Server has a couple of built in functions to convert from radians to degrees and vice versa.
Select Degrees(3.14159), Radians(180.0)
Unfortunately, these functions are slow too. Don't use them.
There was a suggestion early to store your latitude/longitudes in radians instead of degrees. Presumably, this would allow you to simplify the math. Converting from degrees to radians is "simple" math (multiply or divide by a constant). This operation is going to be extremely fast. The distance calculations use several trigonometry functions, which are the slow part. When people talk about lat/long, it is always in degrees (not radians). I wouldn't suggest changing how these values are stored.
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only