chief007
路人甲
路人甲
  • 注册日期2004-10-09
  • 发帖数16
  • QQ
  • 铜币266枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1324回复:2

已知两点的经纬如何计算出两点的距离?

楼主#
更多 发布于:2005-02-18 15:35

<P><b>求助算法:</b></P>
<P>已知两点的经纬如何计算出两点的距离?</P>
喜欢0 评分0
echo2003
点子王
点子王
  • 注册日期2003-07-28
  • 发帖数2453
  • QQ76947571
  • 铜币5473枚
  • 威望1点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
1楼#
发布于:2005-02-18 19:03
<P>转载:已知两点的经纬度
一段实例代码:
---------------------------------------
Option Explicit</P><P>'Class Name:   ClsDistance
'Initiator:    Kewudemao
'Date:         April 28, 2003
'Description:  To calculate the distance between two point based on lat and lon.
'Modify:</P><P>'-----WGS 84 based parameters of earch------
Private Const R_A = 6378137     ' long
Private Const R_B = 6356752     'short
'------------------------------------------
Private Const PI = 3.1415926    'Pi</P><P>Private m_R As Double</P><P>Public Enum Distance_Mode  '
     Miles = 0
     Feet = 1
End Enum</P><P>Private Type PointType
     lat As Double
     lon As Double
End Type</P><P>Private m_PointA As PointType
Private m_PointB As PointType
Private m_DistMode As Distance_Mode
'to get the parameters of DistanceMode
Public Property Get Dist_Mode() As Distance_Mode
    Dist_Mode = m_DistMode
End Property</P><P>Public Property Let Dist_Mode(ByVal vNewValue As Distance_Mode)
   m_DistMode = vNewValue
End Property</P><P>Private Sub Class_Initialize()
     m_R = (R_A + R_B) / 2
End Sub
'get the first point
Public Function SetPointA(lat As Double, lon As Double) As Boolean
     If (lat <= 90 And lat >= -90) And (lon >= -180 And lon <= 180) Then
         m_PointA.lat = lat
         m_PointA.lon = lon
         SetPointA = True
     Else
         SetPointA = False
     End If
End Function
'get the second point
Public Function SetPointB(lat As Double, lon As Double) As Boolean
     If (lat <= 90 And lat >= -90) And (lon >= -180 And lon <= 180) Then
         m_PointB.lat = lat
         m_PointB.lon = lon
         SetPointB = True
     Else
         SetPointB = False
     End If
End Function
'calculate the distance
Public Function GetDistance() As Double
    Dim angAB As Double
    Dim tempV As Double
    Dim tempD As Double
    
    Dim angLatA As Double
    Dim angLatB As Double
    Dim angLonA As Double
    Dim angLonB As Double
    
    
    angLatA = m_PointA.lat / 180 * PI
    angLonA = m_PointA.lon / 180 * PI
    angLatB = m_PointB.lat / 180 * PI
    angLonB = m_PointB.lon / 180 * PI
    
    tempV = VBA.Cos(angLatA) * VBA.Cos(angLatB) * VBA.Cos(angLonB - angLonA) + VBA.Sin(angLatA) * VBA.Sin(angLatB)
    
    Select Case tempV
           Case 1    'angAB = 0
               tempD = 0
          
           Case -1   'angAB = 180
               tempD = m_R * PI
           Case Else 'others
    
                angAB = VBA.Atn(-tempV / VBA.Sqr(-tempV * tempV + 1)) + 2 * VBA.Atn(1)
                tempD = m_R * angAB
     End Select
                
     Select Case m_DistMode
         Case Miles
             tempD = tempD / 1609
         Case Feet
             tempD = tempD / 1609 * 5280
        
      End Select
    
    GetDistance = tempD
    
End Function
-----------------------------------------
</P>
举报 回复(0) 喜欢(0)     评分
wanchengpeng
路人甲
路人甲
  • 注册日期2004-12-12
  • 发帖数3
  • QQ
  • 铜币129枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-02-21 17:36
Distance(x1,y1,x2,y2)
举报 回复(0) 喜欢(0)     评分
游客

返回顶部