# How do I convert the distance between two lat/long points into feet/meters?

I've been reading around the net and everything I find is really confusing. I just need a formula that will get me 95% there. I have a tool that outputs the distance between two lat/long points.

Point 1: 32.773178, -79.920094
Point 2: 32.781666666666666, -79.916666666666671
Distance: 0.0091526545913161624


I would like a fairly simple formula for converting the distance to feet and meters.

Thanks!

• Could you provide a link to the application or specify what application it is in some way? – Raskolnikov Mar 26 '11 at 21:17
• joriki's answer has an unqualified theta expression in the last formula: math.stackexchange.com/suggested-edits/3639 – hoffmanc Dec 22 '11 at 17:30

The tool seems to be just calculating the Euclidean distance between the two points (the square root of the sum of the squared differences between the coordinates). This doesn't make any sense for latitudes and longitudes, which are not coordinates in a Cartesian coordinate system. Not only is this number not a meaningful distance, but it no longer contains the information required to reconstruct a distance from it, so you won't be able to calculate anything meaningful from it; you need to go back to the latitudes and longitudes themselves.

To calculate distances between points given by latitudes and longitudes precisely, you need to know which geoid was used as a reference in specifying them. But since you only want to get within 95% of the answer, you can safely assume that the Earth is a sphere.

There are two possible meanings for "the distance between two points" on a sphere. You can take the Euclidean distance between the two points (the actual points, not their latitude/longitude coordinates like your tool does), or you can take distance along the shortest curve along the surface of the Earth. Again, if you only want to get to within 95% of the answer and the distances are as small as in your example, the difference is negligble, so you can take the Euclidean distance, which is easier to calculate.

To get the Euclidean distance, you can first calculate the Cartesian coordinates of the points from their latitudes and longitudes. Denoting the latitude by $\theta$, the longitude by $\phi$ and the Earth's radius by $R$ (with $R\approx 6371 \mathrm{km}$), these are given by

$$\vec{r}=\left(\begin{array}{c}x\\y\\z\end{array}\right) = \left(\begin{array}{c} R\cos\theta\cos\phi \\ R\cos\theta\sin\phi \\ R\sin\theta \end{array}\right)\;.$$

Then you get the distance between them using

$$d(\vec{r_1},\vec{r_2})=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}\;.$$

Since you seem to have small distances and aren't interested in precision, you can simplify this by expanding the trigonometric functions around one of the points, or, for greater precision, around the midpoint $\theta=(\theta_1+\theta_2)/2$, $\phi=(\phi_1+\phi_2)/2$:

$$\vec{r_2}-\vec{r_1}\approx R\left(\begin{array}{c} \sin\theta\cos\phi(\theta_2-\theta_1)-\cos\theta\sin\phi(\phi_2-\phi_1) \\ \sin\theta\sin\phi(\theta_2-\theta_1)+\cos\theta\cos\phi(\phi_2-\phi_1) \\ \cos\theta(\theta_2-\theta_1) \end{array}\right)\;,$$

$${}$$

$$\lvert\vec{r}_2-\vec{r}_1\rvert\approx R\sqrt{(\theta_2-\theta_1)^2 + \cos^2\theta(\phi_2-\phi_1)^2}\;.$$

• Your $\theta$ is measured down from the pole (from $0$ to $\pi$) while latitude is usually measured from $+90^{\circ}$ (North pole) to $-90^{\circ}$ (South pole) and if you want to take care of altitude the $R$ should be radius from the center, not necessarily $6371$ km. – Ross Millikan Mar 26 '11 at 18:41
• @Ross: Yes, thanks, I just noticed I'd switched $\cos\theta$ and $\sin\theta$; it's already corrected. Concerning altitude, a couple of kilometers of mountains will only make a difference of around one-thousandth, well within the desired accuracy. – joriki Mar 26 '11 at 18:43
• My comment on altitude was prompted by the fact that you show three coordinates and have $\Delta z$ in your original equation. I'll delete my post with the same linearization as yours is more complete. – Ross Millikan Mar 26 '11 at 18:48
• @Ross: I actually thought yours was good to have since mine might look like a complicated mess and yours distilled the essentials of it :-) – joriki Mar 26 '11 at 18:49
• @Ross: $\Delta z$ isn't more or less related to altitude than $\Delta x$ or $\Delta y$; altitude is $\Delta R$. You always need three coordinates doing it this way, altitude or not. Where I live (Berlin), altitude would contribute about equally to $\Delta x$ and $\Delta z$, with $\Delta y\approx0$. – joriki Mar 26 '11 at 18:52

I'm not entirely sure what the distance number your tool is returning means, but here is one way to go about computing the distance you want.

Below is the Spherical Law of Cosines as it appears in UCSMP Functions, Statistics, and Trigonometry, 3rd ed., copied here because the diagram is good and helps with clarity. If $\triangle ABC$ is a spherical triangle with arcs $a$, $b$, and $c$ (meaning the measures of the arcs, not the lengths), then $\cos c=\cos a\cos b+\sin a\sin b\cos C$.

Now, to the specific problem at hand. Let's use the diagram below, also from UCSMP Functions, Statistics, and Trigonometry, 3rd ed., for reference. Let $A$ and $B$ be the two points between which you want to find the distance (for simplicity, I'll assume they are both in the northern hemisphere, and leave extending the solution to any points as an exercise); $N$ and $S$ are the north and south poles, respectively; $C$ and $D$ are the points on the equator that are on the same line of longitude as $A$ and $B$, respectively. Consider spherical $\triangle ABN$. $a=(90°-\text{latitude of point }B)$; $b=(90°-\text{latitude of point }A)$. $N=\text{positive difference in longitude between points }A\text{ and }B$. Use the Spherical Law of Cosines ($\cos n=\cdots$ form) to determine $n$, which is the shortest arc between the two points.

If, for example, $n=10°$, the diameter of the earth is about 12756.2 km, so the distance is $\frac{10°}{360°}\pi\cdot 12756.2\approx 1113.2\text{ km}$.

(graphics from Lesson 5-10 of UCSMP Functions, Statistics, and Trigonometry, 3rd ed., © 2010 Wright Group/McGraw Hill)

If the distances are small, you can use the linearized version: $\Delta x=R \cos(\theta)\Delta \phi, \Delta y=R \Delta \theta$, where $x$ is east-west distance, $\theta$ is latitude (measured with zero at the equator), $y$ is north-south distance, and $\phi$ is longitude. Then the distance is $d=\sqrt{\Delta x^2+ \Delta y^2}$ in whatever units you used for $R$.

Since the question is tagged Mathematica it might be good to provide the Mathematica function, which is (as of version 7):

GeoDistance[{32.773178, -79.920094},
{32.781666666666666,-79.916666666666671}
]

==> 994.652


or, if you want to specify the reference ellipsoid:

GeoDistance[
GeoPosition[{32.773178, -79.920094, 0}, "ITRF00"],
GeoPosition[{32.781666666666666, -79.916666666666671 , 0}, "ITRF00"]
]

• I seem to remember that that function (or whatever its name was in earlier versions) was in one of the Miscellaneous` packages... – J. M. is not a mathematician May 8 '11 at 18:37
• @J.M. It might have been once but it's a built-in function now. – Sjoerd C. de Vries May 8 '11 at 18:47