I am using the Haversine formula to calculate a distance in miles between two (lat, lng) coordinate pairs. (Note: I am aware and okay with limitations in the formula related to the non-spheroidal (ellipsoidal) shape of the Earth.)

I would like to use this formula to solve for either a single latitude or single longitude that is due north, east, west, or south of a given coordinate. This is maybe best illustrated through a diagram; I have the central red point as given and am trying to solve for the 4 outer red points below:

enter image description here

From the central coordinate of (38.0, -77.0), I want to solve (individually) for the 4 missing points at each side of the circle pictured, assuming a distance of 5 miles. So in each equation, I am given a distance and 3 coordinates, and want to solve for the 4th coordinate.

How can I rework Haversine formula to solve for an individual coordinate given the other 3?

What I have tried is to use sympy, but the calculation seems to time out, unless I have a symbol wrong somewhere. I've also tried to invert the formula, but have gotten stuck halfway.

To use the top point (lat2, -77.0) as an example, I'm given the formulas

dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c = 2 * atan2( sqrt(a), sqrt(1-a) )
d = R * c (where R is the radius of the Earth) 

lat1 = radians(38.0)
lon1 = radians(-77.0)
lon2 = radians(-77.0)
d = 5.0

And want to solve for lat2.


2 Answers 2


Let's start from the formula: $$d=2R\arcsin\sqrt{\sin^2\frac{\phi_2-\phi_1}{2}+\cos\phi_1\cos\phi_2\sin^2\frac{\lambda_2-\lambda_1}{2}}$$ So if the longitudes are the same, $\lambda_1=\lambda_2$, then the formula reduces to $$d=R|\phi_2-\phi_1|$$ so $$\phi_2=\phi_1\pm\frac dR$$ You need to check if $\phi_2$ is reasonable (see circles with radii greater than the distance to the poles).

Similarly, to check points at the same latitude, $\phi_1=\phi_2$, $$d=2R\arcsin\left|\cos\phi_1\sin\frac{\lambda_2-\lambda_1}2\right|$$ From here$$\sin\frac{\lambda_2-\lambda_1}2=\pm\frac1{\cos\phi_1}\sin\frac d{2R}$$ This is once again a simple way to get $\lambda_2$, as long as the magnitude of the right hand side is less than $1$. So careful with large distances and around the poles.

  • $\begingroup$ Where does that initial formula come from? Is it a reduction of the one shown in my question, or from somewhere else? $\endgroup$ Jul 19, 2020 at 0:02
  • $\begingroup$ @BradSolomon It's from your first link, the last formula in the first section en.wikipedia.org/wiki/Haversine_formula#Formulation $\endgroup$
    – Andrei
    Jul 19, 2020 at 0:10

The reason you cannot find a formula for determining such a point is that the point may not exist.

Consider walking, say, 1000 feet south from the north pole along the Greenwich meridian. You're at longitude 0, latitude 89.99...

Your circle of latitude is about 6000 feet long --- just a little over a mile. There's no point on that circle for which the haversine formula will return a distance of $5$ miles. So if you want a point "due east" by 5 miles, there is no such thing (at least if distance is determined by the haversine formula).

It's interesting (to me at least) that at a point just about 2.5 miles from the pole, the "east" and "west" points that you're seeking actually coincide, and very nearly coincide with the only rational choice for a "north" point (except that its longitude will differ from yours by 180 degrees).

  • $\begingroup$ Thank you, but not sure that I follow. In my example, the centroid is smack dab in the middle of northern Virginia. How would it not be possible to solve (at the very least with some reduced degree of accuracy/decimal precision) for points 5 miles due east, west, north, and south of that? $\endgroup$ Jul 18, 2020 at 23:32
  • $\begingroup$ I believe what I'm after is something like this or this $\endgroup$ Jul 18, 2020 at 23:34
  • $\begingroup$ My point was that if you want to find a formula for something, that formula will always produce one answer (unless there's a division by zero, or something like square-roots that some folks might treat as multi-valued). If one instance of the problem you've posed has no solution (or multiple solutions), then you're not going to get a formula. You can see this in @Andrei's answer, where the term $d/R$ might be equal to, or much larger than, $2\pi$. If it's a tiny bit less than $2\pi$, then your East point might be just a few feet to the west of you, and vice versa. $\endgroup$ Jul 19, 2020 at 10:09
  • $\begingroup$ Similarly, in your second formula, you'll be computing arcsine of something, but that "something" might be greater than $1$ or less than $-1$, in which case the arcsine is undefined. If your original problem had said "Oh, and I only need a formula for locations where the longitude is nowhere near $\pm 180$ degrees, and the latitude is between $-60$ and $60$ degrees," then there might be some hope of producing a formula for a guaranteed-to-exist correct answer. $\endgroup$ Jul 19, 2020 at 10:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .