# Wrong bearing between two GeoPositions compared to Google Earth

I'm trying to calculate a bearing (degrees, distance) between two points, a and b. From Google Earth I have two points and the following code to calculate the bearing. The input coordinates is in the WGS84 datum (degree, minutes, seconds).

a = {{56, 11, 27.65}, {10, 14, 49.78}};
b = {{56, 11, 27.78}, {10, 14, 54.03}};

aLat = a[[1, 1]] + a[[1, 2]]/60 + a[[1, 3]]/3600;
aLong = a[[2, 1]] + a[[2, 2]]/60 + a[[2, 3]]/3600;
bLat = a[[1, 1]] + b[[1, 2]]/60 + b[[1, 3]]/3600;
bLong = b[[2, 1]] + b[[2, 2]]/60 + b[[2, 3]]/3600;

aPos = GeoPosition[{aLat, aLong}];
bPos = GeoPosition[{bLat, bLong}];

In:= pejling = {GeoDirection[aPos, bPos], GeoDistance[aPos, bPos]}

Out= {Quantity[86.8595, "AngularDegrees"],
Quantity[73.4046, "Meters"]}


So ~87º and ~74 meters.

However, in Google Earth I get ~80º and 146 meters. I can't really figure out why there's a difference. I mean, even if the altitude has something to say, it can't possible be that much. I know the area and it's quite flat.

Also, the heading is somewhat close and the distance in GE is approx 2x the one from Mathematica, but I can't deduce anything from that.

Any ideas?

• @andre I see... But I wonder why there's a difference in my example, and more importantly, which bearing should I trust?
– Argo
Mar 19, 2016 at 22:17
• In the calculation of blat there is an erroneous a term. This is not the cause of your problem, but wrong nevertheless. Mar 20, 2016 at 0:17

The coordinates a = {{56, 11, 27.65}, {10, 14, 49.78}}; b = {{56, 11, 27.78}, {10, 14, 54.03}}; doesn't correspond to what is on the picture.

Try This :

a = {{56, 11, 27.65}, {10, 14, 49.78}};
b = {{56, 11, 27.78}, {10, 14, 54.03}};

aLat = a[[1, 1]] + a[[1, 2]]/60 + a[[1, 3]]/3600;
aLong = a[[2, 1]] + a[[2, 2]]/60 + a[[2, 3]]/3600;
bLat = b[[1, 1]] + b[[1, 2]]/60 + b[[1, 3]]/3600;
bLong = b[[2, 1]] + b[[2, 2]]/60 + b[[2, 3]]/3600;

With[{aLats = ToString[aLat, InputForm],
aLongs = ToString[aLong, InputForm],
bLats = ToString[bLat, InputForm],
bLongs = ToString[bLong, InputForm]},
0xff0000ff|weight:5|" <> aLats <> "," <> aLongs <> "|" <> bLats <>
"," <> bLongs <>
"&size=400x400&sensor=false&maptype=satellite&markers=" <> aLats <>
"," <> aLongs <> "|" <> bLats <> "," <> bLongs]
] The last code use Google Earth API which may become obsolete. In that case one can use the Google Map API, and by the way too URLExecute[] :

a = {{56, 11, 27.65}, {10, 14, 49.78}};
b = {{56, 11, 27.78}, {10, 14, 54.03}};

aLat = a[[1, 1]] + a[[1, 2]]/60 + a[[1, 3]]/3600;
aLong = a[[2, 1]] + a[[2, 2]]/60 + a[[2, 3]]/3600;
bLat = a[[1, 1]] + b[[1, 2]]/60 + b[[1, 3]]/3600;
bLong = b[[2, 1]] + b[[2, 2]]/60 + b[[2, 3]]/3600;
aLats = ToString[aLat, InputForm]
aLongs = ToString[aLong, InputForm]
bLats = ToString[bLat, InputForm]
bLongs = ToString[bLong, InputForm]
centerLats = ToString[(aLat + bLat)/2, InputForm]
centerLongs = ToString[(aLong + bLong)/2, InputForm]

{"maptype" -> "satellite",
"center" -> centerLats <> "," <> centerLongs, "zoom" -> "17",
"size" -> "600x300", "format" -> "png",
"markers" ->
"color:blue|" <> aLats <> "," <> aLongs <> "|" <> bLats <> "," <>
bLongs}, "PNG"] You can also enter the coordinates manually in Google Earth (in the form x°y'z ''). It gives the same result.

Infos :

• Use of the Google Elevation API is subject to a limit of 2,500 requests per day

• I have measured some 100m athletics tracks around the world. First I point the beginning and the end of the tracks with Google Earth, then I export the 2 points to Mathematica, and then I use GeoDistance[]. Here are the amazing results :

{Quantity[100.109, "Meters"], Quantity[99.9603, "Meters"],
Quantity[100.01, "Meters"], Quantity[99.9818, "Meters"]}

• Awesome, thanks! One small request: Let's say I have coordinates start-coordinates {a1, a2, a3, a4} and end-coordinates {b1, b2, b3, b4}. How would one calculate all the bearings from a1 to b1, a2 to b2 and so on? I've tried using a for-loop for extracting the degrees/minutes/seconds and converting to decimal, but without luck.
– Argo
Mar 20, 2016 at 12:40
• @Argo You can do for example : MapThread[GeoDistance,{{a1,a2,a3,a4},{b1,b2,b3,b4}}] Mar 20, 2016 at 17:05