Browse Source

Merge branch 'dev' of https://github.com/kennyboy55/YJMPD-UWP into dev

Yorick Rommers 10 years ago
parent
commit
67a4471901
2 changed files with 15 additions and 12 deletions
  1. 14 11
      YJMPD-UWP/Helpers/Util.cs
  2. 1 1
      YJMPD-UWP/MainPage.xaml.cs

+ 14 - 11
YJMPD-UWP/Helpers/Util.cs

@@ -147,17 +147,20 @@ namespace YJMPD_UWP.Helpers
 
         public static double DegreeBearing(BasicGeoposition pos1, BasicGeoposition pos2)
         {
-            double lat1 = toRadian(pos1.Latitude);
-            double lat2 = toRadian(pos2.Latitude);
-            double dLon = toRadian(pos2.Longitude - pos2.Latitude);
-
-            double dPhi = Math.Log(Math.Tan(lat2 / 2 + Math.PI / 4) / Math.Tan(lat1 / 2 + Math.PI / 4));
-            if (Math.Abs(dLon) > Math.PI) dLon = (dLon > 0) ? -(2 * Math.PI - dLon) : (2 * Math.PI + dLon);
-            double brng = Math.Atan2(dLon, dPhi);
-
-            Debug.WriteLine(brng);
-
-            return ((180.0 * brng / Math.PI) + 360) % 360;
+            var R = 6371000.0;
+            Debug.WriteLine(pos2.Latitude);
+            var φ1 = toRadian(pos1.Latitude);
+            var φ2 = toRadian(pos2.Latitude);
+            var Δφ = toRadian(pos2.Latitude - pos1.Latitude);
+            var Δλ = toRadian(pos2.Longitude - pos2.Longitude);
+
+            var a = Math.Sin(Δφ / 2.0) * Math.Sin(Δφ / 2.0) +
+                    Math.Cos(φ1) * Math.Cos(φ2) *
+                    Math.Sin(Δλ / 2.0)* Math.Sin(Δλ / 2.0);
+            var c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a));
+
+            var d = R * c;
+            return d %360;
         }
 
         private static double toRadian(double val)

+ 1 - 1
YJMPD-UWP/MainPage.xaml.cs

@@ -51,7 +51,7 @@ namespace YJMPD_UWP
         {
             if (e.Handled) return;
 
-            App.Game.MoveToStarted(new BasicGeoposition { Latitude = 51.591403, Longitude = 4.743948 });
+            App.Game.MoveToStarted(new BasicGeoposition { Latitude = 51.591403, Longitude = 40.743948 });
             e.Handled = true;
             return;