Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Equivalent of atn function
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01459871
Message ID:
01459981
Views:
44
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
Map
View

Click here to load this message in the networking platform