2009-10-08 5 views
0

나는 'Haversine'수식에 따라 Google지도에서 2 포인트 (2 위도 & 경도는 입력 매개 변수 임) 사이의 거리를 반환하는 자바 스크립트가 있습니다.Google지도의 Calculatedistance javascript가 정확한가요?

결과가 정확합니까? 이 거리는 로드맵에 따라 계산되거나 2 google point 사이의 짧은 거리입니다.

답변

1

계산시 haversine식이 지구 반경을 차지하지 않는다고 생각합니다. 즉, 두 개의 lat-long 사이에서 먼 거리를 계산할 때 earch의 곡률도 처리해야합니다. (작은 거리에서는 큰 차이가 없지만 먼 거리에서는 차이가납니다.)

거리 원 계산법 (http://www.movable-type.co.uk/scripts/latlong.html)을 사용하여 거리를 계산하여 다양화할 수 있습니다.

SQL을 사용하는 경우 다음 기능을 사용할 수 있습니다.

fUNCTION: F_GREAT_CIRCLE_DISTANCE 
Computes the Great Circle distance in kilometers 
between two points on the Earth using the 
Haversine formula distance calculation. 
Input Parameters: 
@Longitude1 - Longitude in degrees of point 1 
@Latitude1 - Latitude in degrees of point 1 
@Longitude2 - Longitude in degrees of point 2 
@Latitude2 - Latitude in degrees of point 2 


------------------------------------------------- 
create function [dbo].[F_GREAT_CIRCLE_DISTANCE] 
(
@Latitude1 float, 
@Longitude1 float, 
@Latitude2 float, 
@Longitude2 float 
) 
returns float 
as 

begin 
declare @radius float 

declare @lon1 float 
declare @lon2 float 
declare @lat1 float 
declare @lat2 float 

declare @a float 
declare @distance float 

-- Sets average radius of Earth in Kilometers 
set @radius = 6371.0E 

-- Convert degrees to radians 
set @lon1 = radians(@Longitude1) 
set @lon2 = radians(@Longitude2) 
set @lat1 = radians(@Latitude1) 
set @lat2 = radians(@Latitude2) 

set @a = sqrt(square(sin((@[email protected])/2.0E)) + 
(cos(@lat1) * cos(@lat2) * square(sin((@[email protected])/2.0E)))) 

set @distance = 
@radius * (2.0E *asin(case when 1.0E < @a then 1.0E else @a end)) 

return @distance 

end