I am trying to implement a short python function to calculate the heading between two points. In other words if I am at point one, what heading relative to true north would I need to take to get to point two. I have used the following Python implementation which gives me essentially the same results.
from pyproj import Geod
lat1 = 42.73864
lon1 = 111.8052
lat2 = 43.24844
lon2 = 110.6083
geod = Geod(ellps='WGS84')
# This implements the highly accurate Vincenty method
bearing = geod.inv(lon1, lat1, lon2, lat2)[0]
# >>> 60.31358
I have also used the following code that uses a Haversine method
from math import degrees, radians, sin, cos, atan2
def bearing(lat1, lon1, lat2, lon2):
lat, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon1])
dLon = lon2 - lon1
y = sin(dLon) * cos(lat2)
x = cos(lat1)*sin(lat2) - sin(lat1)*cos(lat2)*cos(dLon)
brng = degrees(atan2(y, x))
if brng < 0: brng += 360.0
return brng
With the same inputs from the previous implementation I get a result of 60.313 degrees, which matches the first implementation. However, when I use the Ruler function in google earth I get a result of 15.71 degrees. Furthermore when I activate the grid on google earth that shows the lines of longitude as a reference, 15.71 degrees makes far more sense. Why does the Google Earth implementation differ from the Python implementations?