I want to get distance from the database entry; I've tried the below code so far
SELECT ST_Distance_Sphere( POINT(LNG1, LAT1), POINT(LNG2,LNG2) )* .000621371 ;
Though I've gotten a result, I'm not sure its accurate. I've compared my results with this website (https://www.nhc.noaa.gov/gccalc.shtml)
NOTE: I am trying to get it in miles.
SELECT ST_Distance_Sphere( POINT(-73.98568175135509, 40.7484381443023), POINT(-77.53989898824496, 38.993292463424126) )* .000621371 ; gives a result. ` 224.08790255056905`
is an example. it gives 224 while the website gave 196
CodePudding user response:
The website you used also reports 224 miles - it is just being nautical site, it defaults to nautical miles (n mi), and that gives you 196 n mi. Make sure you select sm
(statute miles - or regular miles), you get 224 sm.
CodePudding user response:
ST_Distance_Sphere does employ Haversine internally.
The website linked in the question was using nmi
instead of mi
, i.e. nautical miles instead of miles.