How do I calculate distance between two latitude, longitude points in miles using standard SQL without trigonometry?
Asked
Active
Viewed 101 times
-2
-
A [mcve] is a great start when asking SQL questions. Don't forget to include table definition(s). – jarlh Jan 12 '22 at 17:40
-
I'd also recommend you to include the distance formula _you_ want to use. – jarlh Jan 12 '22 at 17:41
1 Answers
0
Without trig you get incorrect results. Find an explanation with answer, formula and example here:
https://jonisalonen.com/2014/computing-distance-between-coordinates-can-be-simple-and-fast
Approximation without precision and trig
DECLARE @SqDegreeLatInMiles AS REAL = 4774.81
DECLARE @SqDegreeLongInMiles AS REAL = 2809
-- VA, Zip=23452
DECLARE @Point_A_Lat AS REAL = 36.8366
DECLARE @Point_A_Long AS REAL = 76.0952
-- TX, Zip=75225
DECLARE @Point_B_Lat AS REAL = 32.8644
DECLARE @Point_B_Long AS REAL = 96.7946
DECLARE @DistanceInMiles AS REAL
SET @DistanceInMiles = SQRT (@SqDegreeLatInMiles * POWER(@Point_A_Lat - @Point_B_Lat,2) + @SqDegreeLongInMiles * POWER(@Point_A_Long - @Point_B_Long,2))
PRINT @DistanceInMiles

dbCoder
- 114
- 5