
- distance-between-lon-and-lat
- 11-21-2007
If you were Registered and logged in, you could reply and use other advanced thread options
Matthew wrote:
reproject all your lat-lon data to a local/national grid. These national
grids are commonly in meters or kilometers or something and allow for
simple triangulation calculations based on Pythagoras. Projecting
lat-lon data to local grids can be done using software such as Proj.4
(available through http://proj.maptools.org/ ). However, this approach is
NOT going to work for larger areas. Mum's home to Dad's home will
certainly work, your home to Dad's home will certainly work, I expect
Land's End to John O'Groats will be OK, but London-New York or
London-Ayers Rock will definitely NOT work
Willem
--
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
> Luis Colorado emailed this:
>>> Paul Cooper emailed this:
>>>> wrote:
>>>>> Using Pythagoras on the Ordinance Survey coordinates does not take
>>>>> the curvature of the planet into consideration. In which case it
>>>>> should give me the shorter distance, but it is in fact the longer!
>>>>> Does anyone know why? Also why the difference is as much as 1.7 km,
>>>>> as a margin of error it is quite large when you consider the
>>>>> distance between the points is somewhere about 1000 km?
>>>> Your error is in forgetting that the scale of the mercator projection
>>>> used by the OS is only correct at the central meridian - elsewhere is
>>>> always greater than the true scale. I would expect it to normally give
>>>> too great a value. It isn't a question of "not allowing for the
>>>> curvature of the earth" is is a question of "How much inevitable scale
>>>> distortion is there for the map projection I am using"; remember that
>>>> it is impossible to map the curved surface of the earth onto a flat
>>>> plane without scale distortion.
>>>> wrote:
>>>>> Using Pythagoras on the Ordinance Survey coordinates does not take
>>>>> the curvature of the planet into consideration. In which case it
>>>>> should give me the shorter distance, but it is in fact the longer!
>>>>> Does anyone know why? Also why the difference is as much as 1.7 km,
>>>>> as a margin of error it is quite large when you consider the
>>>>> distance between the points is somewhere about 1000 km?
>>>> Your error is in forgetting that the scale of the mercator projection
>>>> used by the OS is only correct at the central meridian - elsewhere is
>>>> always greater than the true scale. I would expect it to normally give
>>>> too great a value. It isn't a question of "not allowing for the
>>>> curvature of the earth" is is a question of "How much inevitable scale
>>>> distortion is there for the map projection I am using"; remember that
>>>> it is impossible to map the curved surface of the earth onto a flat
>>>> plane without scale distortion.
> > Not, his error is in considering the earth as a perfect sphere, as he
> > does in his calculation with spherical trigonometry formulae. He also
> > uses an aproximation of the curvature radius of the earth that is only
> > valid at some 40º latitude north (not in UK) 1850 per nautical mile
> > (it's 1851.80, not the value used) is valid as a constant to convert
> > meters to nautical miles, but not valid to assume it's the right length
> > of a minute of arc of meridian. That's onli valid at some latitude, but
> > if you consider the earth as an ellipsoid, you'll have to consider the
> > two radii of curvature given by the M(lat) and N(lat) formulas. He is
> > easily to get a 1-2% error in his results as he is getting for sure.
> > does in his calculation with spherical trigonometry formulae. He also
> > uses an aproximation of the curvature radius of the earth that is only
> > valid at some 40º latitude north (not in UK) 1850 per nautical mile
> > (it's 1851.80, not the value used) is valid as a constant to convert
> > meters to nautical miles, but not valid to assume it's the right length
> > of a minute of arc of meridian. That's onli valid at some latitude, but
> > if you consider the earth as an ellipsoid, you'll have to consider the
> > two radii of curvature given by the M(lat) and N(lat) formulas. He is
> > easily to get a 1-2% error in his results as he is getting for sure.
>
> Thanks Luis and everyone - sorry for the delay to get back to you, I
> took a 2 week holiday.
>
> Firstly on the subject of nautical miles to meters conversion, I've had
> a good look on the web and can't find 1851.80 listed or used anywhere
> except in the Wikipedia page (link below) which says it is '=
> 1,851.851851... historical metres'. 1852 is the most prevalent value
> used, but I also found 1853.27 used by a few conversion engines. So now
> I'm thoroughly confused as to which value to use.
>
> http://en.wikipedia.org/wiki/Nautical_mile
>
> I also found another formula for the long/lat distance calculation which
> is similar but uses the mean radius of the Earth, here it is:
>
> distance = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) *
> cos(long2-long1)) * (Mean Radius Of Earth = 6372.797 km)
>
> in code that is:
>
> $v1 = sin($lat1) * sin($lat2);
> $v2 = cos($lat1) * cos($lat2) * cos($lon2 - $lon1);
> $v3 = $v1 + $v2;
> $v4 = acos($v3);
> $meanRadiusOfEarth = 6372.797;
> $v5 = $v4 * $meanRadiusOfEarth;
> $distanceKilometres = $v5;
>
> I know this does not address the problem that the Earth is not a perfect
> sphere, but my maths is not up to dealing with that and I can't find a
> formula online that does it for me. It's not a problem if the accuracy
> of the distances are wrong by a small percent. Would I be better off
> using this new formula?
>
> There's not much in it between the 2 formulas anyway, as these figures
> demonstrate, only 10 km difference in the distance calculated from
> London to Ayers Rock in Australia. Still I'd like to know which you
> think is the more accurate (especially used just for the UK).
>
> The direct distance between My Home (London) and
> Ayers Rock is:
> Old Formula: Kilometres: 14965.439
> New Formula: Kilometres: 14975.530
>
> The direct distance between My Home (London) and
> New York's Empire State Building is:
> Old Formula: Kilometres: 5563.685
> New Formula: Kilometres: 5567.437
>
> The direct distance between Land's End and John O'Groats is:
> (The longest distance possible on the UK mainland).
> Old Formula: Kilometres: 967.691
> New Formula: Kilometres: 968.344
>
> The direct distance between Mum's Home (Oxford) and
> Dad's Home (Oxford) is:
> Old Formula: Kilometres: 0.550
> New Formula: Kilometres: 0.551
>
> The direct distance between My Home (London) and
> Dad's Home (Oxford) is:
> Old Formula: Kilometres: 84.858
> New Formula: Kilometres: 84.915
>
> Many thanks and regards, etc..
If you are dealing with small enough areas you might be better of to
> Thanks Luis and everyone - sorry for the delay to get back to you, I
> took a 2 week holiday.
>
> Firstly on the subject of nautical miles to meters conversion, I've had
> a good look on the web and can't find 1851.80 listed or used anywhere
> except in the Wikipedia page (link below) which says it is '=
> 1,851.851851... historical metres'. 1852 is the most prevalent value
> used, but I also found 1853.27 used by a few conversion engines. So now
> I'm thoroughly confused as to which value to use.
>
> http://en.wikipedia.org/wiki/Nautical_mile
>
> I also found another formula for the long/lat distance calculation which
> is similar but uses the mean radius of the Earth, here it is:
>
> distance = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) *
> cos(long2-long1)) * (Mean Radius Of Earth = 6372.797 km)
>
> in code that is:
>
> $v1 = sin($lat1) * sin($lat2);
> $v2 = cos($lat1) * cos($lat2) * cos($lon2 - $lon1);
> $v3 = $v1 + $v2;
> $v4 = acos($v3);
> $meanRadiusOfEarth = 6372.797;
> $v5 = $v4 * $meanRadiusOfEarth;
> $distanceKilometres = $v5;
>
> I know this does not address the problem that the Earth is not a perfect
> sphere, but my maths is not up to dealing with that and I can't find a
> formula online that does it for me. It's not a problem if the accuracy
> of the distances are wrong by a small percent. Would I be better off
> using this new formula?
>
> There's not much in it between the 2 formulas anyway, as these figures
> demonstrate, only 10 km difference in the distance calculated from
> London to Ayers Rock in Australia. Still I'd like to know which you
> think is the more accurate (especially used just for the UK).
>
> The direct distance between My Home (London) and
> Ayers Rock is:
> Old Formula: Kilometres: 14965.439
> New Formula: Kilometres: 14975.530
>
> The direct distance between My Home (London) and
> New York's Empire State Building is:
> Old Formula: Kilometres: 5563.685
> New Formula: Kilometres: 5567.437
>
> The direct distance between Land's End and John O'Groats is:
> (The longest distance possible on the UK mainland).
> Old Formula: Kilometres: 967.691
> New Formula: Kilometres: 968.344
>
> The direct distance between Mum's Home (Oxford) and
> Dad's Home (Oxford) is:
> Old Formula: Kilometres: 0.550
> New Formula: Kilometres: 0.551
>
> The direct distance between My Home (London) and
> Dad's Home (Oxford) is:
> Old Formula: Kilometres: 84.858
> New Formula: Kilometres: 84.915
>
> Many thanks and regards, etc..
reproject all your lat-lon data to a local/national grid. These national
grids are commonly in meters or kilometers or something and allow for
simple triangulation calculations based on Pythagoras. Projecting
lat-lon data to local grids can be done using software such as Proj.4
(available through http://proj.maptools.org/ ). However, this approach is
NOT going to work for larger areas. Mum's home to Dad's home will
certainly work, your home to Dad's home will certainly work, I expect
Land's End to John O'Groats will be OK, but London-New York or
London-Ayers Rock will definitely NOT work
Willem
--
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
willem van deursen wrote:
Rereading the thread I see you have already been through the local
grids. So nothing new here...............
--
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
Rereading the thread I see you have already been through the local
grids. So nothing new here...............
> If you are dealing with small enough areas you might be better of to
> reproject all your lat-lon data to a local/national grid. These national
> grids are commonly in meters or kilometers or something and allow for
> simple triangulation calculations based on Pythagoras. Projecting
> lat-lon data to local grids can be done using software such as Proj.4
> (available through http://proj.maptools.org/ ). However, this approach is
> NOT going to work for larger areas. Mum's home to Dad's home will
> certainly work, your home to Dad's home will certainly work, I expect
> Land's End to John O'Groats will be OK, but London-New York or
> London-Ayers Rock will definitely NOT work
>
>
> Willem
> reproject all your lat-lon data to a local/national grid. These national
> grids are commonly in meters or kilometers or something and allow for
> simple triangulation calculations based on Pythagoras. Projecting
> lat-lon data to local grids can be done using software such as Proj.4
> (available through http://proj.maptools.org/ ). However, this approach is
> NOT going to work for larger areas. Mum's home to Dad's home will
> certainly work, your home to Dad's home will certainly work, I expect
> Land's End to John O'Groats will be OK, but London-New York or
> London-Ayers Rock will definitely NOT work
>
>
> Willem
--
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
willem van deursen emailed this:
Thanks anyway Willem.
> willem van deursen wrote:
>
> Rereading the thread I see you have already been through the local
> grids. So nothing new here...............
>
> Rereading the thread I see you have already been through the local
> grids. So nothing new here...............
Thanks anyway Willem.
>> If you are dealing with small enough areas you might be better of to
>> reproject all your lat-lon data to a local/national grid. These
>> national grids are commonly in meters or kilometers or something and
>> allow for simple triangulation calculations based on Pythagoras.
>> Projecting lat-lon data to local grids can be done using software such
>> as Proj.4 (available through http://proj.maptools.org/ ). However, this
>> approach is NOT going to work for larger areas. Mum's home to Dad's
>> home will certainly work, your home to Dad's home will certainly work,
>> I expect Land's End to John O'Groats will be OK, but London-New York
>> or London-Ayers Rock will definitely NOT work
>> Willem
>> reproject all your lat-lon data to a local/national grid. These
>> national grids are commonly in meters or kilometers or something and
>> allow for simple triangulation calculations based on Pythagoras.
>> Projecting lat-lon data to local grids can be done using software such
>> as Proj.4 (available through http://proj.maptools.org/ ). However, this
>> approach is NOT going to work for larger areas. Mum's home to Dad's
>> home will certainly work, your home to Dad's home will certainly work,
>> I expect Land's End to John O'Groats will be OK, but London-New York
>> or London-Ayers Rock will definitely NOT work
>> Willem
>
>
>
> Luis Colorado emailed this:
>> Not, his error is in considering the earth as a perfect sphere,
>> as he does in his calculation with spherical trigonometry formulae.
>> He also uses an aproximation of the curvature radius of the earth
>> that is only valid at some 40=BA latitude north (not in UK) 1850 per
>> nautical mile (it's 1851.80, not the value used) is valid as a
>> constant to convert meters to nautical miles, but not valid to
>> assume it's the right length of a minute of arc of meridian.
>> That's onli valid at some latitude, but if you consider the earth
>> as an ellipsoid, you'll have to consider the two radii of curvature
>> given by the M(lat) and N(lat) formulas. He is easily to get a 1-2%
>> error in his results as he is getting for sure.
>> as he does in his calculation with spherical trigonometry formulae.
>> He also uses an aproximation of the curvature radius of the earth
>> that is only valid at some 40=BA latitude north (not in UK) 1850 per
>> nautical mile (it's 1851.80, not the value used) is valid as a
>> constant to convert meters to nautical miles, but not valid to
>> assume it's the right length of a minute of arc of meridian.
>> That's onli valid at some latitude, but if you consider the earth
>> as an ellipsoid, you'll have to consider the two radii of curvature
>> given by the M(lat) and N(lat) formulas. He is easily to get a 1-2%
>> error in his results as he is getting for sure.
> Thanks Luis and everyone - sorry for the delay to get back to you,
> I took a 2 week holiday.
> Firstly on the subject of nautical miles to meters conversion, I've
> had a good look on the web and can't find 1851.80 listed or used
> anywhere except in the Wikipedia page (link below) which says it
> is '=3D 1,851.851851... historical metres'. 1852 is the most prevalent
> value used, but I also found 1853.27 used by a few conversion engines.
> So now I'm thoroughly confused as to which value to use.
> http://en.wikipedia.org/wiki/Nautical_mile
> I also found another formula for the long/lat distance calculation
> which is similar but uses the mean radius of the Earth, here it is:
> distance =3D acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) *
> cos(long2-long1)) * (Mean Radius Of Earth =3D 6372.797 km)
> in code that is:
> $v1 =3D sin($lat1) * sin($lat2);
> $v2 =3D cos($lat1) * cos($lat2) * cos($lon2 - $lon1);
> $v3 =3D $v1 + $v2;
> $v4 =3D acos($v3);
> $meanRadiusOfEarth =3D 6372.797;
> $v5 =3D $v4 * $meanRadiusOfEarth;
> $distanceKilometres =3D $v5;
> I know this does not address the problem that the Earth is not a
> perfect sphere, but my maths is not up to dealing with that and
> I can't find a formula online that does it for me. It's not a
> problem if the accuracy of the distances are wrong by a small
> percent. Would I be better off using this new formula?
> I took a 2 week holiday.
> Firstly on the subject of nautical miles to meters conversion, I've
> had a good look on the web and can't find 1851.80 listed or used
> anywhere except in the Wikipedia page (link below) which says it
> is '=3D 1,851.851851... historical metres'. 1852 is the most prevalent
> value used, but I also found 1853.27 used by a few conversion engines.
> So now I'm thoroughly confused as to which value to use.
> http://en.wikipedia.org/wiki/Nautical_mile
> I also found another formula for the long/lat distance calculation
> which is similar but uses the mean radius of the Earth, here it is:
> distance =3D acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) *
> cos(long2-long1)) * (Mean Radius Of Earth =3D 6372.797 km)
> in code that is:
> $v1 =3D sin($lat1) * sin($lat2);
> $v2 =3D cos($lat1) * cos($lat2) * cos($lon2 - $lon1);
> $v3 =3D $v1 + $v2;
> $v4 =3D acos($v3);
> $meanRadiusOfEarth =3D 6372.797;
> $v5 =3D $v4 * $meanRadiusOfEarth;
> $distanceKilometres =3D $v5;
> I know this does not address the problem that the Earth is not a
> perfect sphere, but my maths is not up to dealing with that and
> I can't find a formula online that does it for me. It's not a
> problem if the accuracy of the distances are wrong by a small
> percent. Would I be better off using this new formula?
Yes!!!
"The mean radius of Earth =3D 6372.797 km" *IS* the best fit "great-
circle radius" for an ellipsoid, as it is a closed-form approximation
of all of the mean circumferences of an ellipsoid----not just the mean
north-south meridional circumference.
The most rudimentary approximation of the mean ellipsoidal
circumference, "Cr", is the simple average of the mean meridional
circumference, "Mr", and the equatorial radius, a:
Mr ~=3D~ .5 * [a + b];
Cr ~=3D~ .5 * [Mr + a],
~=3D~ .5 * [.5*(a + b) + a] =3D .25 * [3*a + b];
Just as the arcradius can vary at a given point (depending on the
direction being faced), due to different ways an oblique circumference
can be delineated (geodetically vs. geographically) and defined
(circumferential arc vs. the actual linear radius under the arc), the
"best fit" approximation is the ellipsoidal quadratic mean radius,
"Qr":
Qr =3D [.25(3*a^2 + b^2)]^.5 ~=3D~ Cr;
which, for WGS84, approximately equals 6372.797556!
> There's not much in it between the 2 formulas anyway, as these figures
> demonstrate, only 10 km difference in the distance calculated from
> London to Ayers Rock in Australia. Still I'd like to know which you
> think is the more accurate (especially used just for the UK).
> demonstrate, only 10 km difference in the distance calculated from
> London to Ayers Rock in Australia. Still I'd like to know which you
> think is the more accurate (especially used just for the UK).
It's not so much a question of being "accurate", but having a
conceptual basing and establishing a definitive equation.
Judge for yourself: The mid-oblique circumference (delineated
geodetically, with respect to latitude) is found at Lat_1 =3D 0, Lat_2 =3D
45=B0 and Long_2 - Long_1 =3D 90=B0----find the distance and divide by half-=
pi. Now compare what you get with all of the established "mean
radii": Which is closest?!? P=3D)
I did a "more verbose explanation" in Talk:Earth:
http://en.wikipedia.org/wiki/Talk:Earth/Archive_7#Mean_radius
~Kaimbridge~
-----
Wikipedia--Contributor Home Page:
http://en.wikipedia.org/wiki/User:Kaimbridge
***** Void Where Permitted; Limit 0 Per Customer. *****
The great circle distance used in your formulas doesn't assume the earth =
as an ellipsoid, but a spherical surface. And you are using just a =
radius of curvature to get distances, but not considering the different =
radii along the N-S axis and the E-W axis. These are approximate =
formulas to get rough values, but you must not consider them when =
calculating distances to some precission.
I should use the cartesian coordinates and formulae to get better =
results (the one you used first in your post), just consider the =
correction coefficient applied at the site of measure (K is a locally =
constant value ranging from 0.999x to 1.000x to correct scale due to the =
non planar surface of the earth when using some kind of grid coordinates =
---perhaps you have it pointed to somewhere in the chart used---) This =
K coefficient depends on the projection used to map earth surface and =
the point you are considering.
as an ellipsoid, but a spherical surface. And you are using just a =
radius of curvature to get distances, but not considering the different =
radii along the N-S axis and the E-W axis. These are approximate =
formulas to get rough values, but you must not consider them when =
calculating distances to some precission.
I should use the cartesian coordinates and formulae to get better =
results (the one you used first in your post), just consider the =
correction coefficient applied at the site of measure (K is a locally =
constant value ranging from 0.999x to 1.000x to correct scale due to the =
non planar surface of the earth when using some kind of grid coordinates =
---perhaps you have it pointed to somewhere in the chart used---) This =
K coefficient depends on the projection used to map earth surface and =
the point you are considering.
> Sorry if I am gatecrashing this thread, but maybe someone can help me =
with=20
> a same-topic question, cos my maths isn't up to it. :(
>=20
> For any 2 locations in the UK I have both the UK Ordinance Survey=20
> coordinates and the long/lat coordinates.
>=20
> I'm calculating the distance between 2 points in 2 ways.
>=20
> i) Using Pythagoras on the Ordinance Survey coordinates, like this:
>=20
> distance in metres =3D
> sqrt ( ((OS1_x - OS2_x) ^2) + ((OS1_y - OS2_y) ^2) )
>=20
>=20
> ii) Calculating the 'great circle' distance using long/lat and the =
formula=20
>=20
> For any 2 locations in the UK I have both the UK Ordinance Survey=20
> coordinates and the long/lat coordinates.
>=20
> I'm calculating the distance between 2 points in 2 ways.
>=20
> i) Using Pythagoras on the Ordinance Survey coordinates, like this:
>=20
> distance in metres =3D
> sqrt ( ((OS1_x - OS2_x) ^2) + ((OS1_y - OS2_y) ^2) )
>=20
>=20
> ii) Calculating the 'great circle' distance using long/lat and the =
> on the page linked below, that someone in this thread was kind enough =
to=20
> post. http://williams.best.vwh.net/avform.htm#Dist
>=20
> The formulas on that page are:
> ---------------------------------------------------------------
> The great circle distance d between two points with coordinates=20
> and is given by:
>=20
> d=3Dacos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
>=20
> A mathematically equivalent formula, which is less subject to rounding =
>=20
> The formulas on that page are:
> ---------------------------------------------------------------
> The great circle distance d between two points with coordinates=20
> and is given by:
>=20
> d=3Dacos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
>=20
> A mathematically equivalent formula, which is less subject to rounding =
> error for short distances is:
>=20
> d=3D2*asin(sqrt((sin((lat1-lat2)/2))^2 +
> cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
> ---------------------------------------------------------------
>=20
> Both 'great circle' formulas of ii) give me the same results for the =
few=20
>=20
> d=3D2*asin(sqrt((sin((lat1-lat2)/2))^2 +
> cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
> ---------------------------------------------------------------
>=20
> Both 'great circle' formulas of ii) give me the same results for the =
> UK coordinates I've so far tested which is re-assuring.
>=20
> Land's End and John O'Groats are the 2 locations furthest away from =
each=20
>=20
> Land's End and John O'Groats are the 2 locations furthest away from =
> other on the UK mainland. The distance between them which I get from =
using=20
> Pythagoras on the Ordinance Survey coordinates is 969425.120 metres =
and=20
> from using the long/lat great circle method is 967691.445 metres. The=20
> difference between the values is 1733.675 metres.
>=20
> Using Pythagoras on the Ordinance Survey coordinates does not take the =
> difference between the values is 1733.675 metres.
>=20
> Using Pythagoras on the Ordinance Survey coordinates does not take the =
> curvature of the planet into consideration. In which case it should =
give=20
> me the shorter distance, but it is in fact the longer! Does anyone =
know=20
> why? Also why the difference is as much as 1.7 km, as a margin of =
error it=20
> is quite large when you consider the distance between the points is=20
> somewhere about 1000 km?
>=20
> Many thanks all. Regards, etc..
>=20
> PS. In case it is needed here's the (pseudo) code of my long/lat =
distance=20
> somewhere about 1000 km?
>=20
> Many thanks all. Regards, etc..
>=20
> PS. In case it is needed here's the (pseudo) code of my long/lat =
> calculation:
>=20
>=20
> // Make sure all long and lat are positive
>=20
> if (lat1 < 0) lat1 =3D lat1 * -1;
> if (lon1 < 0) lon1 =3D lon1 * -1;
> if (lat2 < 0) lat2 =3D lat2 * -1;
> if (lon2 < 0) lon2 =3D lon2 * -1;
>=20
> // Convert decimal long/lat to radians
> // angle_radians =3D (pi / 180) * angle_degrees
>=20
> lat1 =3D (pi / 180) * lat1;
> lon1 =3D (pi / 180) * lon1;
> lat2 =3D (pi / 180) * lat2;
> lon2 =3D (pi / 180) * lon2;
>=20
> // Calculate the distance
> // d=3Dacos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
>=20
> val1 =3D sin(lat1) * sin(lat2);
> val2 =3D cos(lat1) * cos(lat2) * cos(lon1 - lon2);
> val3 =3D v1 + v2;
> distance =3D acos(val3);
>=20
> // Convert the distance to nautical miles
> // distance_nm=3D ( (180*60) / pi ) * distance_radians
>=20
> distanceNauticalMiles =3D ( (180 * 60) / pi) * distance;
>=20
> // Note: the nautical mile is currently defined to be 1852 meters
>=20
> metres =3D distanceNauticalMiles * 1852;
>=20
> return metres;
>=20
>=20
> // Make sure all long and lat are positive
>=20
> if (lat1 < 0) lat1 =3D lat1 * -1;
> if (lon1 < 0) lon1 =3D lon1 * -1;
> if (lat2 < 0) lat2 =3D lat2 * -1;
> if (lon2 < 0) lon2 =3D lon2 * -1;
>=20
> // Convert decimal long/lat to radians
> // angle_radians =3D (pi / 180) * angle_degrees
>=20
> lat1 =3D (pi / 180) * lat1;
> lon1 =3D (pi / 180) * lon1;
> lat2 =3D (pi / 180) * lat2;
> lon2 =3D (pi / 180) * lon2;
>=20
> // Calculate the distance
> // d=3Dacos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
>=20
> val1 =3D sin(lat1) * sin(lat2);
> val2 =3D cos(lat1) * cos(lat2) * cos(lon1 - lon2);
> val3 =3D v1 + v2;
> distance =3D acos(val3);
>=20
> // Convert the distance to nautical miles
> // distance_nm=3D ( (180*60) / pi ) * distance_radians
>=20
> distanceNauticalMiles =3D ( (180 * 60) / pi) * distance;
>=20
> // Note: the nautical mile is currently defined to be 1852 meters
>=20
> metres =3D distanceNauticalMiles * 1852;
>=20
> return metres;
- Distance from one city to another city
- Tomtom GPS
- 2011-08-05
- How is distance calculated?
- Satellite Navigation
- 2012-02-08
- Google Maps - straight line distance
- Garmin GPS
- 2011-06-10
- Distance to destination on Nuvi 850?
- Garmin GPS
- 2009-07-27
- Road distance
- Satellite Navigation
- 2010-05-10
