diff --git a/src/org/openstreetmap/josm/data/coor/LatLon.java b/src/org/openstreetmap/josm/data/coor/LatLon.java
index 084bc9c..280a7de 100644
--- a/src/org/openstreetmap/josm/data/coor/LatLon.java
+++ b/src/org/openstreetmap/josm/data/coor/LatLon.java
@@ -177,23 +177,23 @@ public class LatLon extends Coordinate {
 
     /**
      * Returns the heading, in radians, that you have to use to get from
-     * this lat/lon to another.
+     * this lat/lon to another. North=0, East=Pi/2
      *
      * @param other the "destination" position
      * @return heading
      */
     public double heading(LatLon other) {
-        double rv;
-        if (other.lat() == lat()) {
-            rv = (other.lon()>lon() ? Math.PI / 2 : Math.PI * 3 / 2);
-        } else {
-            rv = Math.atan((other.lon()-lon())/(other.lat()-lat()));
-            if (rv < 0) {
-                rv += Math.PI;
-            }
-            if (other.lon() < lon()) {
-                rv += Math.PI;
-            }
+        double dlon = other.lon() - lon();
+        double dlat = other.lat() - lat();
+        if (dlon > 180.0) {
+            dlon -= 360.0;
+        }
+        if (dlon < -180.0) {
+            dlon += 360.0;
+        }
+        double rv = Math.atan2(dlon * cos(Math.toRadians(lat())), dlat);
+        if (rv < 0.0) {
+            rv += 2.0 * Math.PI;
         }
         return rv;
     }
