緯度と経度を使用した 2 つの場所間の距離は Google の見解と大きく異なります
-
05-07-2019 - |
質問
これを解決するために数日費やしましたが、問題を正確に特定できないようです。SQL 2005 データベースに緯度と経度を Decimal(18,8) として保存しています。これらはすべて Google にクエリして取得したものです。
これら 2 つの場所の場合: から:10715 Downsville Pike Ste 100 MD 21740 宛先:444 East College Ave Ste 120 ステート カレッジ PA、16801
距離が「飛ぶように」であることを考慮すると、私の結果はまだ遠いです。この例では、結果は 21.32 マイルと表示されますが、Google マップでは 144 マイルと表示されます。
さらにイライラさせるのは、次のサイトを見つけたことだと思います。 http://jan.ucc.nau.edu/~cvm/latlongdist.html そして私とほぼ同じ結果が得られました。
私の関数とクエリは次のとおりです。
機能:距離の計算
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) )
緯度プラス距離
RETURN (SELECT @StartLatitude + SQRT(@Distance * @Distance / 4766.8999155991))
経度プラス距離
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)
解決
CalculateDistance 関数で @Temp を 1 または -1 にリセットするのはなぜですか?
アップデート. 。さて、上記のことは気にしないでください。緯度/経度は正しいですか?私は次を使用して計算しました ジオコーダー.us:
10715 Downsville Pike Ste 100, 21740 戻り値 (39.607483, -77.753747)
444 E College Ave Ste 120, 16801 戻り値 (39.607483, -77.753747)
数式 (上記で返された精度であるため、小数点以下 6 桁に四捨五入) を使用すると、次のようになります。
sin(39.607483/57.295779) * sin(40.798594/57.295779)
+ cos(39.607483/57.295779) * cos(40.798594/57.295779)
* cos(77.753747/57.295779 - 77.856110/57.295779) = 0.99978299
3958.75586574 * arccos(0.99978299) = 82.4748331
それは合理的だと思われます。