Calculating Distance between latitude/longitude coordinates

Bullflip

New Member
Joined
Jun 2, 2020
Messages
19
Office Version
  1. 365
Platform
  1. Windows
I am having a hard time trying to calculate the distance in miles between latitude/longitude coordinates. I have 1 datapoint where I would like to calculate the distance of the other coordinates from that 1 datapoint.

On the excel sheet, the top coordinates highlighted in yellow is the reference point. I tried using this formula, but it isn't working:

=ACOS(COS(RADIANS(90-A2)*COS(RADIANS(90-A3))+SIN(RADIANS(90-A2))*SIN(RADIANS(90-A3))*COS(RADIANS(B2-B3)))*3959)

If anyone knows the formula, please let me know. Thank you!
 

Attachments

  • Capture.JPG
    Capture.JPG
    73.6 KB · Views: 548

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I recall a similar question that arose about a year ago...here is a link to that post:
I'll have a look at your specific question. There are several models that could be used. The link that appears in my post should connect to a helpful resource that I used back then.
 
Upvote 0
Something like this uses the same approach outlined in the link found in my previous post:
MrExcel20210615.xlsx
ABC
1Latitude (Decimal Degrees)Longitude (Decimal Degrees)Distance (km)
241.88329-87.6536Reference
341.9494-87.66567.42
441.87307-87.63372.00
Bullflip
Cell Formulas
RangeFormula
C3:C4C3=IFERROR(6371*ACOS(SIN($A$2*PI()/180)*SIN($A3*PI()/180) + COS($A$2*PI()/180)*COS($A3*PI()/180)*COS($B3*PI()/180 - $B$2*PI()/180)),"")


...or this version, since it appears that you want distance expressed in units of miles:
MrExcel20210615.xlsx
ABC
1Latitude (Decimal Degrees)Longitude (Decimal Degrees)Distance (mi)
241.88329-87.6536Reference
341.9494-87.66564.61
441.87307-87.63371.24
Bullflip
Cell Formulas
RangeFormula
C3:C4C3=IFERROR(3959*ACOS(SIN($A$2*PI()/180)*SIN($A3*PI()/180) + COS($A$2*PI()/180)*COS($A3*PI()/180)*COS($B3*PI()/180 - $B$2*PI()/180)),"")
 
Last edited:
Upvote 0
Something like this uses the same approach outlined in the link found in my previous post:
MrExcel20210615.xlsx
ABC
1Latitude (Decimal Degrees)Longitude (Decimal Degrees)Distance (km)
241.88329-87.6536Reference
341.9494-87.66567.42
441.87307-87.63372.00
Bullflip
Cell Formulas
RangeFormula
C3:C4C3=IFERROR(6371*ACOS(SIN($A$2*PI()/180)*SIN($A3*PI()/180) + COS($A$2*PI()/180)*COS($A3*PI()/180)*COS($B3*PI()/180 - $B$2*PI()/180)),"")


...or this version, since it appears that you want distance expressed in units of miles:
MrExcel20210615.xlsx
ABC
1Latitude (Decimal Degrees)Longitude (Decimal Degrees)Distance (mi)
241.88329-87.6536Reference
341.9494-87.66564.61
441.87307-87.63371.24
Bullflip
Cell Formulas
RangeFormula
C3:C4C3=IFERROR(3959*ACOS(SIN($A$2*PI()/180)*SIN($A3*PI()/180) + COS($A$2*PI()/180)*COS($A3*PI()/180)*COS($B3*PI()/180 - $B$2*PI()/180)),"")
Hi! Thank you so much for taking the time to help me. I will take a look at this tomorrow and let you know the result. Thanks again!
 
Upvote 0
To help with your comparisons/reviews, this version parallels your original, including the use of the RADIANS functions, but examine the terms in the Spherical Law of Cosines. The biggest issues I noted were: 1) The cosine of the difference of longitudes goes with the other cosine terms, and 2) The complement (i.e., subtraction from 90 degrees) of the latitudes and longitudes is not necessary.
MrExcel20210615.xlsx
ABC
1Latitude (Decimal Degrees)Longitude (Decimal Degrees)Distance (mi)
241.88329-87.6536Reference
341.9494-87.66564.61
441.87307-87.63371.24
588673450.02
6-1056814.38
Bullflip (2)
Cell Formulas
RangeFormula
C3:C6C3=ACOS(COS(RADIANS($A$2))*COS(RADIANS($A3))*COS(RADIANS($B3-$B$2))+SIN(RADIANS($A$2))*SIN(RADIANS($A3)))*3959
 
Upvote 0
To help with your comparisons/reviews, this version parallels your original, including the use of the RADIANS functions, but examine the terms in the Spherical Law of Cosines. The biggest issues I noted were: 1) The cosine of the difference of longitudes goes with the other cosine terms, and 2) The complement (i.e., subtraction from 90 degrees) of the latitudes and longitudes is not necessary.
MrExcel20210615.xlsx
ABC
1Latitude (Decimal Degrees)Longitude (Decimal Degrees)Distance (mi)
241.88329-87.6536Reference
341.9494-87.66564.61
441.87307-87.63371.24
588673450.02
6-1056814.38
Bullflip (2)
Cell Formulas
RangeFormula
C3:C6C3=ACOS(COS(RADIANS($A$2))*COS(RADIANS($A3))*COS(RADIANS($B3-$B$2))+SIN(RADIANS($A$2))*SIN(RADIANS($A3)))*3959
Hi, I was able to review it this morning and it works perfectly! Thank you for your help again. Much appreciated! I'm going to dig in more to the formula to get a better understanding of it.
 
Upvote 0
Hi all and best wishes for 2022,
Regarding to the question, there are two ways for calculating the distance between two points on earth and each of them has advantages and disadvantages.

1-) Loxodromic Path:
Defined as a curve between two points wich angle with respect to the meridians is constant.
 
Upvote 0
Sorry ....... I continue...
LOXODROME:
Advantage. As Heading is defined as the angle between the pretended path and the meridians, Loxodrome allows for navigation at constant heading (rhumb).
Advantage. Easy to be drawn (as a right line) on Mercator Navigation Charts.
Disadvantages. At any sphere, the minimum distance between two points is defined by a cutting plane that passes through the given points and the center of the sphere. Hence the Loxodrome distance will result longer than this.

ORTODROMIC or Great Circle:
Advantages. Is the minimum distance path between two points on any given sphere.
Disadvantages. Requires a constant heading change during the navigation making it more difficult to follow than Loxodrome.
Disadvantage. Maximum latitude along the path could be too high and too close to rough weather or arctic areas.
Disadvantage. Hard to be drawn on a Mercator Navigation Chart where meridians are forced to be parallel.

Real practice: Unless navigating low latitudes or really long distances the rhumb line is traced by Loxodrome pathlines or by a combination of both.

Definition of Nautical mile: Is the lenght of one minute-arc of a Meridian. It makes nosence converting this unit to meters as it is an arc and not a linear distance. From another point of view the Nautical mile depends on number PI wich is an irrational number, hence any convertion to linear units will result irrational as well.

How to calculate....
Points.
Point1 (lat1,LON1)
Point2(Lat2,LON2)

incLON= LON2-LON1
incLAT= Lat2 - Lat1


ORTODROMIC:
Spherical geometry required.
D= 60 ACOS(sin(lat1) sin(lat2)+cos(lat1) cos(lat2) cos(IncLON)) ----------> 60 to covert from degrees to Nautical miles.

For departure heading


Rd = acos (sin(Lat2)- sin(Lat1) cos(D))/(cos(Lat2) sin(D)) --------------> With all data in degrees.

Heading, as said above, changes and requires re-calculation along the path for any new point.


LOXODROME:
Being this curve an helicoid with a variable radius that runs up to the pole, N or S depending on the initial heading.... a few intermediate calculations must be performed.

If a way to correct for the helicoid deformation is found, calculations could be solved by planar geometry.
This change in the radius is proportional to the cosine of the latitude. Which latitude? In fact a differential increment should be taken but in practice the thing is solved by taking the middle latitude between departure and arrival.
A new concept is required in order to go on. "Departure" is defined as the distance along the middle latitude parallel between departure an arrival meridians.
Hence given incLON calculated above, the relation with Departure is given by...

middle latitude= (Lat2+Lat1)/2


D= 60 incLON cos(middle latitude)
...... Remark: Multiplied by 60 in order to get Nautical miles.

An now Loxodrome or rhumb line distance is given by ....

d= SQRT (D² + (60 incLat)²)

Heading is constant along the whole sailing and is given by:

H= atan(D/incLat)
With D and incLat in the same units (degrees or miles)


REMARK: In Excel, trigonometric functions "prefer" radians. In order to get distances resulting radias must be converted to degrees and muiltiplied by 60.
 
Upvote 0
All:

Here is the source code for a VBA function that does the calculation. Open the Developer -> VisualBasic window, add a module to your workbook, and paste in this code:

VBA Code:
' Function LatLongDist() - Calulates the arc distance between two Lat, Long where...
'   lat and long are in degrees in the form degrees=ddd + mm/60 + sss/3600
'                       i.e. 29 44' 00" = 29+44/60+0/3600 = 29.7333333
'   first point is (lat1, long1)
'   second point is (lat2, long2)
'   EarthRadius is the radius of the earth, use KM for calculations in KM, miles for calculations in miles, and NM for calculations in NM
'   EarthRadius = 3440 NM
'   EarthRadius = 6371 KM  (6378.137 KM at the Equator, 6356.752 at poles, use 6371 [volumetric mean radius) for most calculations)
'   EarthRadius = 3959 Miles

Function LatLongDist(lat1, long1, lat2, long2, EarthRadius)
    Dim cos1, cos2, sin1, sin2, lat1rad, lat2rad, lond1rad, long2rad, _
        straightLineDist, arcDist, x1, y1, z1, x2, y2, z2, radius As Double
    
    radius = EarthRadius
    '
    'Convert Lat Long to Radians
    '
    lat1rad = lat1 / 180 * 3.14159
    lat2rad = lat2 / 180 * 3.14159
    long1rad = long1 / 180 * 3.14159
    long2rad = long2 / 180 * 3.14159
    '
    ' Convert (R,T,r) (Rho, Theta, radius) Polar coordinates into standard (x,y,z) coordinates
    '
    x1 = Sin(lat1rad) * Cos(long1rad) * radius
    y1 = Sin(lat1rad) * Sin(long1rad) * radius
    z1 = Cos(lat1rad) * radius
    x2 = Sin(lat2rad) * Cos(long2rad) * radius
    y2 = Sin(lat2rad) * Sin(long2rad) * radius
    z2 = Cos(lat2rad) * radius
    '
    ' Calc straight line distance between 2 points in 3D space
    '
    straightLineDist = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2)
    '
    ' Use law of cosines to calculate arc distance
    '
    arcDist = WorksheetFunction.Acos(1 - (straightLineDist ^ 2 / (2 * radius ^ 2))) * radius
    '
    'return arc distance
    '
    LatLongDist = arcDist
    '
    ' comment above and uncomment below to return straight line distance
    '
    'LatLongDist = straightLineDist
    '
End Function
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top