public void Start() { if (_geo == null) { // Load last knowns. if (_cache.Lat.HasValue && _cache.Long.HasValue) { LastKnownLocation = new Location { Latitude = _cache.Lat.Value, Longitude = _cache.Long.Value, Altitude = 0, HorizontalAccuracy = double.NaN, VerticalAccuracy = double.NaN, }; } PriorityQueue.AddWorkItem(() => { try { _geo = new GeoCoordinateWatcher(GeoPositionAccuracy.High); _geo.MovementThreshold = 20; // meters _geo.StatusChanged += OnStatusChanged; _geo.PositionChanged += OnPositionChanged; _geo.Start(); } catch { } }); } }
private void OnStatusChanged(object sender, GeoPositionStatusChangedEventArgs e) { Status = e.Status; #if GEO_DEBUG Debug.WriteLine("*******"); Debug.WriteLine(""); Debug.WriteLine("GEO: Status is {0}", _status); Debug.WriteLine(""); #endif switch (e.Status) { case GeoPositionStatus.Initializing: break; case GeoPositionStatus.Disabled: //throw new InvalidOperationException(); break; case GeoPositionStatus.NoData: #if DEBUG if (seattle) { double lat = isBoka ? 47.60487905922638 : 47.60643068740198; double @long = isBoka ? -122.33625054359436 : -122.3319536447525; Debug.WriteLine("GEO: Using some favorite Seattle coordinates for debug-time emulator work."); LastKnownLocation = new Location { Latitude = lat, Longitude = @long, VerticalAccuracy = double.NaN, HorizontalAccuracy = 350, Altitude = 0, }; } else { if (isWorldwide) { Debug.WriteLine("GEO: Using a worldwide coordinate for debug-time emulator work."); LastKnownLocation = new Location { // sweden //Latitude = 55.603331, //Longitude = 13.001303, // russia //Latitude = 54.741903, //Longitude = 20.532171, // NYC //Latitude = 40.760838, //Longitude = -73.983436, // Shanghai French Concession //Latitude = 31.209058, //Longitude = 121.470015, // Winter Garden, FL Latitude = 28.564889, Longitude = -81.587257, // London, Trafalgar Square //Latitude = 51.507828, //Longitude = -0.128628, VerticalAccuracy = double.NaN, HorizontalAccuracy = 100, Altitude = 0, }; } else { // redmond Debug.WriteLine("GEO: Using Redmond work coordinates for debug-time emulator work."); LastKnownLocation = new Location { Latitude = 47.6372299194336, Longitude = -122.133848190308, VerticalAccuracy = double.NaN, HorizontalAccuracy = 100, Altitude = 0, }; } } Status = GeoPositionStatus.Ready; #endif break; case GeoPositionStatus.Ready: break; } var handler = StatusChanged; if (handler != null) { handler(this, e); } }