I am testing SQL Server STDistance function in the following way:
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POINT(53.553813 9.99158)', 4326);
SET @h = geography::STGeomFromText('POINT(52.5234051 13.4113)', 4326);
SELECT @g.STDistance(@h);
These points represent, respectively, Hamburg and Berlin.
The STDistance
call above returns 394612.166639773
(aprox. 394km). However, on Google Earth/Maps, when I calculate the straight line between the two points above, I get aprox. 254km.
If I understood correctly, both SQL Server SRID 4326
and Google Earth represent/use the WGS84
reference system, so I don't know what else could be causing this difference.
Any ideas?
Best Answer
Bill Huber gave the right answer in the comments. I delayed the answer by running the NGS inverse tool incorrectly.
It looks like confusion between latitude and longitude order. I did put the coordinates in the wrong order when I used the NGS inverse tool. Stupid of me! If I enter values correctly, the geodesic distance is 256414.3059 m. If I enter the coordinates incorrectly (latitude = 13.4113 rather than longitude = 13.4113), the geodesic distance is 394612.1666 m.
Thus, ST_Distance in SQL Server requires coordinates in longitude, latitude order.