Search code examples
windows-store-appswindows-store

How can I detect if an user has stopped walking using C# in my windows store app?


I need to do this for my app, but I'm not sure how. Currently I'm trying to achieve it using Geolocator and a Timer.


Solution

    1. Declare a Geolocator with a fixed ReportInterval
    2. Store the locations
    3. With the help of these methods compare current with stored location to detect movement

      public const double EARTH_RADIUS_M = 6371000
      
      private static double ToRad(double val)
      {
          return val * (Math.PI / 180);
      }
      
      public static double GetDistanceM(double lat0, double lng0, double lat1, double lng1)
      {
          double dLat = ToRad(lat1 - lat0);
          double dLon = ToRad(lng1 - lng0);
      
          double a = Math.Pow(Math.Sin(dLat / 2), 2) +
                     Math.Cos(ToRad(lat0)) * Math.Cos(ToRad(lat1)) *
                     Math.Pow(Math.Sin(dLon / 2), 2);
      
          double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
      
          double distance = EARTH_RADIUS_M * c;
          return distance;
      }
      
      1. Considerations for windows 10:

        private async void StartLocationExtensionSession()
        {
            session = new ExtendedExecutionSession();
            session.Description = "Location Tracker";
            session.Reason = ExtendedExecutionReason.LocationTracking;
            var result = await session.RequestExtensionAsync();
        }
        
      2. Considerations for Windows Phone 8:

    https://msdn.microsoft.com/en-us/library/windows/apps/jj662935(v=vs.105).aspx

    1. Be happy with your new dynamic MovementThreshold ;)!