using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Device.Location;

namespace Windows7LocationApiDemo {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

        GeoCoordinateWatcher geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);

        public MainWindow() {
            InitializeComponent();

            geoWatcher.MovementThreshold = 10; //in meters!!!
            geoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(geoWatcher_StatusChanged);
            geoWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(geoWatcher_PositionChanged);
            geoWatcher.Start();
        }

        private void Window_Closed(object sender, EventArgs e) {
            geoWatcher.Stop();
        }


        void geoWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) {
            lblLatitude.Content = e.Position.Location.Latitude.ToString(@"\N 0.00000;\S 0.00000;\-");
            lblLongitude.Content = e.Position.Location.Longitude.ToString(@"\E 0.00000;\W 0.00000;\-");
        }

        void geoWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) {
            lblStatus.Content = e.Status.ToString();
        }

    }
}
