Thursday, April 26, 2012

Getting Location information in MvvmCross

I've added a lesson in the tutorial that shows the IMvxGeoLocationWatcher location fetching interface being used.
      private void DoStartStop()
      {
          if (!IsStarted)
          {
              _watcher.Start(new MvxGeoLocationOptions() { EnableHighAccuracy = true }, OnNewLocation, OnError);
          }
          else
          {
              _watcher.Stop();
          }
          IsStarted = !IsStarted;
      }
      private void OnError(MvxLocationError error)
      {
          // TODO - shuold handle the error better than this really!
          LastError = error.Code.ToString();
      }
      private void OnNewLocation(MvxGeoLocation location)
      {
          if (location != null && location.Coordinates != null)
          {
              Lat = location.Coordinates.Latitude;
              Lng = location.Coordinates.Longitude;
          }
      }  
This seems to work OK on:
I haven't yet written the code for WinRT...

No comments:

Post a Comment