Hi all,
I'm having a problem getting an accurate distance for my Lat/Long program.
I have used several methods of calculation which are set out below:
While they separately give the same resulting distance, they do not give the accurate distance as I require.
As an example:
Using WGS - 84 ellipsoid radius of 6378.137 Kms
and co-ordinates of:
Lat1: 51:37:42.66 N
Lon1: 3:55:44.09 W
Lat2: 51:23:51.51 N
Lon2: 1:18:3.61 W
The resulting distance using the methods below of :183.8513160623843 kms
While trying several Web sites using WGS -84
their results are 184.220....kms
Two of the methods I've used for calculations are basically,
Method 1:
Dim Lat1 As Double, Long1 As Double, Lat2 As Double, Long2 As Double
Dim EarthRadius, Angle, Distance As Double
EarthRadius = 6378.137 ' WGS -84 kilometers?
lat1 = txtlatdeg.Text
lat2 = txtlatdeg2.Text
long1 = txtlondeg.Text
long2 = txtlondeg2.Text
Angle = ACos(SinD(Lat1) * SinD(Lat2) + CosD(Lat1) * CosD(Lat2) * CosD(Long2 - Long1))
Distance = EarthRadius * Angle
txtdistance = Distance
...........................................................
Method 2:
Dim lat1 As Double, long1 As Double, lat2 As Double, long2 As Double
DEGREES_TO_RADIANS = (cPI / 180.0)
EARTH_RADIUS = 6378.137
lat1 =latt1.Text
lat2 = latt2.Text
long1 = lonn1.Text
long2 =lonn2.Text
rlat1 = DEGREES_TO_RADIANS * lat1
rlong1 = DEGREES_TO_RADIANS * long1
rlat2 = DEGREES_TO_RADIANS * lat2
rlong2 = DEGREES_TO_RADIANS * long2
p1 = Cos(rlat1) * Cos(rlong1) * Cos(rlat2) * Cos(rlong2)
p2 = Cos(rlat1) * Sin(rlong1) * Cos(rlat2) * Sin(rlong2)
p3 = Sin(rlat1) * Sin(rlat2)
ret = p1 + p2 + p3
If ret = 1 Then Return 0
ret = ACos(ret)
ret = (ret * EARTH_RADIUS)
Result.Text = ret
Return ret
.......................................
Any help will be appreciated:
Thanks
Rob
I'm having a problem getting an accurate distance for my Lat/Long program.
I have used several methods of calculation which are set out below:
While they separately give the same resulting distance, they do not give the accurate distance as I require.
As an example:
Using WGS - 84 ellipsoid radius of 6378.137 Kms
and co-ordinates of:
Lat1: 51:37:42.66 N
Lon1: 3:55:44.09 W
Lat2: 51:23:51.51 N
Lon2: 1:18:3.61 W
The resulting distance using the methods below of :183.8513160623843 kms
While trying several Web sites using WGS -84
their results are 184.220....kms
Two of the methods I've used for calculations are basically,
Method 1:
Dim Lat1 As Double, Long1 As Double, Lat2 As Double, Long2 As Double
Dim EarthRadius, Angle, Distance As Double
EarthRadius = 6378.137 ' WGS -84 kilometers?
lat1 = txtlatdeg.Text
lat2 = txtlatdeg2.Text
long1 = txtlondeg.Text
long2 = txtlondeg2.Text
Angle = ACos(SinD(Lat1) * SinD(Lat2) + CosD(Lat1) * CosD(Lat2) * CosD(Long2 - Long1))
Distance = EarthRadius * Angle
txtdistance = Distance
...........................................................
Method 2:
Dim lat1 As Double, long1 As Double, lat2 As Double, long2 As Double
DEGREES_TO_RADIANS = (cPI / 180.0)
EARTH_RADIUS = 6378.137
lat1 =latt1.Text
lat2 = latt2.Text
long1 = lonn1.Text
long2 =lonn2.Text
rlat1 = DEGREES_TO_RADIANS * lat1
rlong1 = DEGREES_TO_RADIANS * long1
rlat2 = DEGREES_TO_RADIANS * lat2
rlong2 = DEGREES_TO_RADIANS * long2
p1 = Cos(rlat1) * Cos(rlong1) * Cos(rlat2) * Cos(rlong2)
p2 = Cos(rlat1) * Sin(rlong1) * Cos(rlat2) * Sin(rlong2)
p3 = Sin(rlat1) * Sin(rlat2)
ret = p1 + p2 + p3
If ret = 1 Then Return 0
ret = ACos(ret)
ret = (ret * EARTH_RADIUS)
Result.Text = ret
Return ret
.......................................
Any help will be appreciated:
Thanks
Rob