문제

나는 이것을 알아 내려고 며칠을 보냈고 문제를 정확히 찾아 내지 못하는 것 같습니다. 위도와 경도를 10 진수 (18,8)로 저장하는 SQL 2005 데이터베이스가 있습니다.

이 두 위치의 경우 : 출처 : 10715 Downsville Pike Ste 100 MD 21740 ~ : 444 East College Ave Ste 120 State College PA, 16801

그 거리는 '까마귀가 날아갈 때'가 될 것입니다. 내 결과는 여전히 벗어납니다. 이 예에서는 내 결과에 21.32 마일이 표시되지만 Google Maps는 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) )

latitudeplusdistance

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)
도움이 되었습니까?

해결책

계산 기능에서 @temp을 1 또는 -1로 재설정하는 이유는 무엇입니까?

업데이트. 좋아요, 위의 것을 신경 쓰지 마십시오. 위도 / 경도가 맞다고 확신합니까? 다음 사용을 계산합니다 geocoder.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

합리적으로 보입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top