我正在使用geography.STDistance()来返回两个单点位置之间的距离.我很好奇哪个测量用于返回值?是KM,里程还是其他?
我得到的结果高达250k,但我不知道我的TSQL是否做错了,因为这些是历史位置(即它们不再存在)所以我不能只是快速查找.
declare @p1 geography
declare @p2 geography
SELECT @p1 = Location from tblLocations where Id = 1
SELECT @p2 = Location from tblLocations where Id = 2
select @p1.STDistance(@p2)
Run Code Online (Sandbox Code Playgroud) 这是我的代码.
Create Table [dbo].[MajorCities]
(
[CityID] int Identity(1,1),
[CityName] varchar(60),
[Latitude] float,
[Longitude] float,
GeoRef Geography
)
INSERT INTO dbo.[MajorCities] values
('New Delhi, India', 28.6, 77.2, null),
('Paris, France', 48.86667, 2.3333, null),
('Rio de Janeiro, Brazil', -22.9, -43.23333, null),
('Sydney, Australia', -33.88306, 151.21667, null),
('New York City, USA', 40.78333, -73.96667, null)
select * from [MajorCities]
UPDATE [dbo].[MajorCities]
SET [GeoRef] = geography::STPointFromText ('POINT (' + CAST ([Longitude] AS VARCHAR (20)) + ' ' +
CAST ([Latitude] AS VARCHAR (20)) + ')', …Run Code Online (Sandbox Code Playgroud)