Created
September 19, 2013 04:41
-
-
Save engalar/6619202 to your computer and use it in GitHub Desktop.
经纬度计算距离宏
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'计算两经纬度之间距离=cal_long_lat(经度1,纬度1,经度2,纬度2) | |
Public Function Cal_Long_Lat(ByVal long1 As Double, ByVal lat1 As Double, ByVal long2 As Double, ByVal lat2 As Double) As Double | |
Const PI As Double = 3.1415926535 | |
Dim AngleLong1, AngleLat1, AngleLong2, AngleLat2 As Double | |
AngleLong1 = long1 * PI / 180 | |
AngleLat1 = lat1 * PI / 180 | |
AngleLong2 = long2 * PI / 180 | |
AngleLat2 = lat2 * PI / 180 | |
Dim sinX, cosX As Double | |
sinX = Sin(AngleLat1) * Sin(AngleLat2) | |
cosX = Cos(AngleLat1) * Cos(AngleLat2) * Cos(AngleLong2 - AngleLong1) | |
x = sinX + cosX | |
On Error Resume Next | |
ax = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1) | |
Cal_Long_Lat = 6368160 * ax | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment