위도 경도를 이용한 거리 계산
-- 각 지점의 위도 경도 구하기 (아래 사이트에서 구함, kakao api 이용해도 가능)
-- https://tablog.neocities.org/keywordposition
-- 검색한 위도 경도를 이용해 서울역에서 용인두산위브까지의 거리 SQL서버로 구하기
-- Parse 는 대소문자를 구분하고, STGeomFromText 에서 SRID를 4236으로 고정한 값으로 계산함
-- https://learn.microsoft.com/en-us/sql/t-sql/spatial-geography/parse-geography-data-type?view=sql-server-ver16
-- https://learn.microsoft.com/ko-kr/sql/t-sql/spatial-geometry/stgeomfromtext-geometry-data-type?view=sql-server-ver16
-- POINT는 점으로 계산, LINESTRING 은 선분으로 계산 WKT 표현임, 모든 데이터베이스에 이런거 다 지원함
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::Parse('POINT(126.9720686318752 37.55593878839654)');
SET @h = geography::Parse('POINT(127.15001085373893 37.28340610861977)');
SELECT @g.STDistance(@h); --this is the distance in meters
GO
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POINT(126.9720686318752 37.55593878839654)', 4326);
SET @h = geography::STGeomFromText('POINT(127.15001085373893 37.28340610861977)', 4326);
SELECT @g.STDistance(@h); --this is the distance in meters
GO
-- SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);