sql server 根据经纬度计算两点间距离
DECLARE @BJ GEOGRAPHY DECLARE @XT GEOGRAPHY
SELECT @BJ= geography::Point('39.92889', '116.38833', 4326) SELECT @XT = geography::Point('37.0630556', '114.441667', 4326) ELECT @BJ AS Beijing, @XT AS Xingtai, 'The distance is ' + CAST(@BJ.STDistance(@XT)/1000 AS VARCHAR(MAX)) + ' km' AS Distance
或者简写:
SELECT top 1 CAST(geography::Point('39.92889', '116.38833', 4326).STDistance(geography::Point ('37.0630556', '114.4941667', 4326))/1000 AS FLOAT) FROM 表名