I've added a lesson in the tutorial that shows the
IMvxGeoLocationWatcher
location fetching interface being used.
See the sample in https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.Core/ViewModels/Lessons/LocationViewModel.cs with simple ViewModel code like:
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:
- WP7 - https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.UI.WindowsPhone/Views/Lessons/LocationView.xaml
- Droid - https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.UI.Droid/Views/Lessons/LocationView.cs
- Touch - https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.UI.Touch/VIews/Lessons/LocationView.cs
I haven't yet written the code for WinRT...
No comments:
Post a Comment