private void RefreshLocationStatuses() { // Handles first cases where no location is found. GeoPositionStatus locStatus = Model.Core.DeviceLocationStatus; // Location service is disabled or unavailable. if (locStatus == GeoPositionStatus.Disabled) { LocationWarning = "This device's location services are disabled or not working."; } // Location service is OK but no data was found. else if (locStatus == GeoPositionStatus.NoData) { LocationWarning = "Location services are enabled but gave no data so far."; } else if (locStatus == GeoPositionStatus.Initializing) { LocationWarning = null; } if (locStatus != GeoPositionStatus.Ready) { LocationStatus = "Status: " + locStatus.ToString(); LocationAccuracyStatus = null; return; } // Location service is OK and data should be here. GeoCoordinate loc = Model.Core.DeviceLocation; // Data is not valid. if (loc == null || loc.IsUnknown) { LocationWarning = "Location services are enabled but only gave invalid data so far."; LocationStatus = "Status: " + locStatus.ToString(); return; } // Data is valid. bool isPoorAccuracy = loc.HorizontalAccuracy >= MaxGoodLocationAccuracy; LocationStatus = loc.ToZonePoint().ToString(GeoCoordinateUnit.DegreesMinutes); LocationAccuracyStatus = String.Format("Accuracy: {0:0.00}m ({1})", loc.HorizontalAccuracy, isPoorAccuracy ? "POOR" : "OK"); // Shows a warning for low accuracy. if (isPoorAccuracy) { LocationWarning = "Very low accuracy. Try looking for clear sky."; } else { LocationWarning = null; } }
// <summary> // Creates an instance of GeoCoordinateWatcherInternal with the specified desired accuracy // </summary> public GeoCoordinateWatcherInternal(GeoPositionAccuracy desiredAccuracy) { // // Create the native location object on a worker thread, so that it exists // in a multithreaded apartment. // ThreadPool.QueueUserWorkItem(new WaitCallback(this.CreateHandler), desiredAccuracy); Utility.Trace("GeoCoordinateWatcherInternal.ctor:" + " desiredAccuracy: " + desiredAccuracy.ToString() + " m_latLongRegistered: " + m_latLongRegistered.ToString() + " m_civicAddrRegistered: " + m_civicAddrRegistered.ToString() + " m_latLongStatus: " + m_latLongStatus.ToString() + " m_curStatus: " + m_curStatus.ToString()); }
/// <summary> /// This is where the application responds to new status information. In this case, it simply /// displays the location information. If emulation is enabled and the status is Ready, a /// new thread is launched for position emulation. This mimics the behaviour of the live data, /// where location data doesn't arrive until the LocationService status is Ready. /// </summary> /// <param name="status"></param> void StatusChanged(GeoPositionStatus status) { // Display the current status statusTextBlock.Text = status.ToString(); // If emulation is being used and the status is Ready, start the position emulation thread if (status == GeoPositionStatus.Ready && useEmulation) { positionEmulationThread = new Thread(StartPositionEmulation); positionEmulationThread.Start(); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); spriteBatch.DrawString(spriteFont, currentState.ToString(), new Vector2(0, 0), Color.White); if (SavedGeoCoord != null && CurrentGeoCoord != null) { spriteBatch.DrawString(spriteFont, string.Format("Distance: {0:0.00}meters, {1:0.00}feet\n" + "Speed: {2:0.00}meters/s, {3:0.00}km/h, {4:0.00}mph", distance, distance * 3.2808399, CurrentGeoCoord.Location.Speed, CurrentGeoCoord.Location.Speed * 3.6, CurrentGeoCoord.Location.Speed * 3.6 * 0.621371192), new Vector2(0, 480), Color.White); if (buttonToggleNorthUp.Text == "Toggle: North up") { // North up mode spriteBatch.Draw(texCircle, new Vector2((graphics.PreferredBackBufferWidth - texCircle.Width) / 2, graphics.PreferredBackBufferHeight - texCircle.Height - 10), Color.White); spriteBatch.Draw(texArrow, new Rectangle((graphics.PreferredBackBufferWidth) / 2, graphics.PreferredBackBufferHeight - texCircle.Height / 2 - 10, texCircle.Width, texCircle.Height), null, Color.White, (float)DegreeToRadian(CurrentGeoCoord.Location.Course), // Your current movement direction new Vector2(128, 128), SpriteEffects.None, 0); spriteBatch.Draw(texSpot, new Rectangle((graphics.PreferredBackBufferWidth) / 2, graphics.PreferredBackBufferHeight - texCircle.Height / 2 - 10, texCircle.Width, texCircle.Height), null, Color.White, (float)DegreeToRadian(bearing), // In what direction your saved location is related to your current location new Vector2(128, 128), SpriteEffects.None, 0); } else { // Your direction up mode // Every thing is the same as above except the all angles are being shifted by (-curGeoCoord.Location.Course), // so that your movement direction is always pointing up spriteBatch.Draw(texCircle, new Rectangle((graphics.PreferredBackBufferWidth) / 2, graphics.PreferredBackBufferHeight - texCircle.Height / 2 - 10, texCircle.Width, texCircle.Height), null, Color.White, -(float)DegreeToRadian(CurrentGeoCoord.Location.Course), new Vector2(128, 128), SpriteEffects.None, 0); spriteBatch.Draw(texArrow, new Rectangle((graphics.PreferredBackBufferWidth) / 2, graphics.PreferredBackBufferHeight - texCircle.Height / 2 - 10, texCircle.Width, texCircle.Height), null, Color.White, 0, new Vector2(128, 128), SpriteEffects.None, 0); spriteBatch.Draw(texSpot, new Rectangle((graphics.PreferredBackBufferWidth) / 2, graphics.PreferredBackBufferHeight - texCircle.Height / 2 - 10, texCircle.Width, texCircle.Height), null, Color.White, (float)DegreeToRadian(bearing) - (float)DegreeToRadian(CurrentGeoCoord.Location.Course), new Vector2(128, 128), SpriteEffects.None, 0); } } spriteBatch.End(); // Some ui elements combine 3D geometry with text so they can't render within a SpriteBatch.Begin/End section. for (int b = 0; b < uiElementList.Count; b++) { uiElementList[b].Draw(spriteBatch); } base.Draw(gameTime); }