我花了几天的时间试图找出这一个,似乎无法查明问题。我有一个SQL 2005数据库存储经度和纬度为十进制(18,8),我通过查询Google收到的所有数据。使用经度和纬度的两个位置之间的距离关闭谷歌说的
考虑到距离将是“直线距离”,我的成绩依然遥远。在这个例子中,我的结果是21.32英里,但谷歌地图说144英里。
我认为使它更令人沮丧的打顶是我发现这个网站:http://jan.ucc.nau.edu/~cvm/latlongdist.html,并提出几乎与我完全相同的结果。
这里是我的功能和查询:
功能: CalculateDistance
DECLARE @Temp FLOAT
SET @Temp = SIN(@Latitude1/57.2957795130823) *
SIN(@Latitude2/57.2957795130823) +
COS(@Latitude1/57.2957795130823) * COS(@Latitude2/57.2957795130823) *
COS(@Longitude2/57.2957795130823 - @Longitude1/57.2957795130823)
IF @Temp > 1
SET @Temp = 1
ELSE IF @Temp < -1
SET @Temp = -1
RETURN (3958.75586574 * ACOS(@Temp))
LatitudePlusDistance
RETURN (SELECT @StartLatitude + SQRT(@Distance * @Distance/4766.8999155991))
LongitudePlusDistance
RETURN (SELECT @StartLongitude + SQRT(@Distance * @Distance/
(4784.39411916406 *
COS(2 * @StartLatitude/114.591559026165) *
COS(2 * @StartLatitude/114.591559026165))))
查询:
DECLARE @Longitude DECIMAL(18,8),
@Latitude DECIMAL(18,8),
@MinLongitude DECIMAL(18,8),
@MaxLongitude DECIMAL(18,8),
@MinLatitude DECIMAL(18,8),
@MaxLatitude DECIMAL(18,8),
@WithinMiles DECIMAL(2)
Set @Latitude = -77.856052
Set @Longitude = 40.799159
Set @WithinMiles = 50
-- Calculate the Max Lat/Long
SELECT @MaxLongitude = dbo.LongitudePlusDistance(@Longitude, @Latitude,
@WithinMiles),
@MaxLatitude = dbo.LatitudePlusDistance(@Latitude, @WithinMiles)
-- Calculate the min lat/long
SELECT @MinLatitude = 2 * @Latitude - @MaxLatitude,
@MinLongitude = 2 * @Longitude - @MaxLongitude
SELECT Top 20 *, dbo.CalculateDistance(@Longitude, @Latitude,
LocationLongitude, LocationLatitude) as 'Distance'
FROM Location
WHERE LocationLongitude Between @MinLongitude And @MaxLongitude
And LocationLatitude Between @MinLatitude And @MaxLatitude
And dbo.CalculateDistance(@Longitude, @Latitude, LocationLongitude,
LocationLatitude) <= @WithinMiles
ORDER BY dbo.CalculateDistance(@Longitude, @Latitude, LocationLongitude,
LocationLatitude)
您链接到的其他网站是从1997年,当地球比今天小得多(由于离心力)。我会和Google一起去看这个。 :) – MusiGenesis 2009-10-22 00:25:12
是的,在谷歌之前,这个世界变得更小了。但是这并不能帮助我达到正确的距离。 – Mikecancook 2009-10-22 01:06:17
我发现了另一个网站来计算结果,它与我一直在得到的一样,21英里和一些变化。 http://www.movable-type.co.uk/scripts/latlong.html 尝试这些位置: 长/纬度 40.799159,-77.856052 40.22018,-78.140205 – Mikecancook 2009-10-22 02:08:05