# Calculating azimuth from two points, both having latitude/longtiude?

How to calculate the Azimuth angle between two points on the surface of the earth if i ONLY have the lat/long of them?

Here is an example image: the azimuth angle is X which i want to calculate AND the angle to the magnetic pole. The first question is addressed at Bearing/Course/Heading in WGS84 ellipsoid model [since deleted by its asker] and How to Calculate North?. The second question does not have a "mathematical" solution in the sense of a formula because it requires a dataset showing magnetic north at all points of the earth.

• the first link is broken. – gansub Aug 2 '18 at 14:48

Let's define an example with three points:

To calculate the azimuth angle between each coordinate pair, you can use GeographicLib, for example the online tool. Find the `fazi1` azimuth from the inverse geodesic to get the forward azimuth from p1 to the second point:

So the absolute difference between these two azimuths should be the angle you are looking for, 103.76106083. And again, this is the angle between MP and p2 as "viewed" from p1.

• I don't know why, the site just didn't give the same results. – Majed DH Oct 30 '17 at 10:05
• You need to find the `fazi1` result. There are several other language bindings, including JavaScript and Python, so you don't need a website tool. – Mike T Oct 30 '17 at 18:24

Sorry i forgot the question, even I had it's answer couple of days after i had posted it.

## First Question:

In that time i was searching for a formula to give the same results as the heading between two points in Google Earth, which I've found here ( first answer on Google ) , it has a lot of Math formulas for a lot of problems (distance,bearing,intersections of path... etc) along with google maps examples for most of the cases. AND Javascript source code for each one.

I quote from it:

``````var φ1 = this.lat.toRadians(), φ2 = point.lat.toRadians();
var y = Math.sin(Δλ) * Math.cos(φ2);
var x = Math.cos(φ1)*Math.sin(φ2) -
Math.sin(φ1)*Math.cos(φ2)*Math.cos(Δλ);
var θ = Math.atan2(y, x);

return (θ.toDegrees()+360) % 360;
``````

where φ is Lat, λ is Long , both in Degrees.

All of the past equations are relative to the true north, and we know there is the `Declination` part which is - as Wikipedia says:

Magnetic declination or variation is the angle on the horizontal plane between magnetic north and true north

I've found here the application to calculate the magnetic declination using the point lat/long, attitude, and the year to calculate the declination.

It gives you the declination from the data set of `World Magnetic Model` (of 2015 apparently).

For example, using the software:

At my location at year 2017 and attitude of 600 meters the declination is around 4.8 degrees to the East and this is the deference between true north and magnetic north in my area, in other words if i had a compass it would point to 4.8 degrees to the east of true geographic north.

• Note that the functions and equations shown by "Movable Type Scripts" are based on a spherical earth, and are slightly less accurate than methods based on an oblate spheroid (e.g. WGS84). – Mike T Oct 30 '17 at 22:21
• It gave the same results as my client wanted, the same numbers Google Earth had. – Majed DH Oct 31 '17 at 12:43