public App() { UnhandledException += Application_UnhandledException; if (System.Diagnostics.Debugger.IsAttached) { // Zähler für die aktuelle Bildrate anzeigen. //Application.Current.Host.Settings.EnableFrameRateCounter = true; // Bereiche der Anwendung hervorheben, die mit jedem Bild neu gezeichnet werden. //Application.Current.Host.Settings.EnableRedrawRegions = true; // Nicht produktiven Visualisierungsmodus für die Analyse aktivieren, // in dem GPU-beschleunigte Bereiche der Seite farbig hervorgehoben werden. //Application.Current.Host.Settings.EnableCacheVisualization = true; } InitializeComponent(); InitializePhoneApplication(); if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator) lastKnownPosition = new GeoPosition<GeoCoordinate>(DateTimeOffset.Now, new GeoCoordinate(48.422362, 9.957327)); }
/// <summary> /// Starts processing of nmea file using passed delay action. /// Send GeoPosition message to message bus. /// </summary> public void Start(Action<TimeSpan> delayAction) { _positionDateTime = null; _position = new GeoPosition(); string line; _isStarted = true; while ((line = _parser.ReadLine()) != null) { if (!_isStarted) break; if (line.Length <= 0) continue; var message = _parser.ParseLine(line); if (message == null || !CanSetPositionFromMessage(message) || _position.Date.Year < 2001) continue; DateTime currentDateTime = _position.DateTime; if (_positionDateTime != null) { var sleepTime = currentDateTime - _positionDateTime.Value; delayAction(sleepTime); _messageBus.Send(_position); } _positionDateTime = currentDateTime; } _isStarted = false; FireDone(); }
public Pushpin(GeoPosition<GeoCoordinate> position, string type, GeoPosition<GeoCoordinate> referencePosition = null, RoutedEventHandler pushpinEvent = null) { _referencePosition = referencePosition; _pushpinEvent = pushpinEvent; _position = position; _type = type; _pushpinOverlay = GetPushpinOverlay(); }
public void ChangePosition(DateTimeOffset offset, GeoCoordinate coordinate) { Position = new GeoPosition<GeoCoordinate>(offset, coordinate); if (PositionChanged != null) { PositionChanged(null, new GeoPositionChangedEventArgs<GeoCoordinate>(Position)); } }
private void OnPositionAvailable(GeoPosition<GeoCoordinate> position) { if (PositionAvailable != null) { Deployment.Current.Dispatcher.BeginInvoke(() => PositionAvailable(this, new EventArgs<Location>(new Location(position.Location.Latitude, position.Location.Longitude)))); } }
/// <summary> /// Use a GeoPosition instance to populate a ParseObject /// </summary> /// <param name="g">the GeoPosition</param> /// <param name="p">the ParseObject</param> public static void GeoPositionSetParseObject(GeoPosition<GeoCoordinate> g, ParseObject p) { p[LOCATION] = new ParseGeoPoint(ToParseNaN(g.Location.Latitude), ToParseNaN(g.Location.Longitude)); p[TIME_STAMP] = g.Timestamp.DateTime; p[ALTITUDE] = ToParseNaN(g.Location.Altitude); p[HORIZONTAL_ACCURACY] = ToParseNaN(g.Location.HorizontalAccuracy); p[VERTICAL_ACCURACY] = ToParseNaN(g.Location.VerticalAccuracy); p[SPEED] = ToParseNaN(g.Location.Speed); p[COURSE] = ToParseNaN(g.Location.Course); }
private const double R = 3440; //miglia nautiche #endregion Fields #region Methods /// <summary> /// Calcola la distanza in MIGLIA NAUTICHE (nm) tra due punti geografici. Il calcolo è svolto con la /// formula di Aversine /// </summary> /// <param name="pos1">punto uno</param> /// <param name="pos2">punto 2</param> /// <returns>la distanza in miglia nautiche</returns> public static double CalulateDistance(GeoPosition pos1, GeoPosition pos2) { double dLat = toRadian(pos2.Latitude - pos1.Latitude); double dLon = toRadian(pos2.Longitude - pos1.Longitude); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(toRadian(pos1.Latitude)) * Math.Cos(toRadian(pos2.Latitude)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a))); double d = R * c; return d; }
void myWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) { myPosition = myWatcher.Position; currentLocation = myWatcher.Position.Location; if (isInDriveMode) { DrawMyCurrentRoute(currentLocation); } LocationManager.GetLocationName(UpdateLocation, myPosition.Location.Latitude.ToString(), myPosition.Location.Longitude.ToString()); }
private Position GetPosition(GeoPosition<GeoCoordinate> position) { if (position.Location.IsUnknown) { return null; } return new Position { Latitude = position.Location.Latitude, Longitude = position.Location.Longitude, Speed = position.Location.Speed, UtcTicks = position.Timestamp.UtcTicks }; }
public void Construction_with_course_lesser_than_zero_throws_execption() { var expectedTimestamp = TimeSpan.Zero; double expectedLatitude = -89.0; double expectedLongitude = 13.34046; double expectedPressureAltitude = 100.0; double expectedGpsAltitude = 101.0; double expectedCourse = -3.45; double expectedSpeed = 0.1; var coord = new GeoPosition(expectedTimestamp, expectedLatitude, expectedLongitude, expectedPressureAltitude, expectedGpsAltitude, expectedCourse, expectedSpeed); }
public void Construction_with_latitude_smaller_than_90_throws_execption() { var expectedTimestamp = TimeSpan.Zero; double expectedLatitude = -90.5; double expectedLongitude = 13.34046; double expectedPressureAltitude = 100.0; double expectedGpsAltitude = 101.0; double expectedCourse = 3.45; double expectedSpeed = 30.0; var coord = new GeoPosition(expectedTimestamp, expectedLatitude, expectedLongitude, expectedPressureAltitude, expectedGpsAltitude, expectedCourse, expectedSpeed); }
/// <summary> /// Convert a ParseObject to its GeoPosition counterpart /// </summary> /// <param name="p">the ParseObject instance</param> /// <returns>the GeoPosition object</returns> public static GeoPosition<GeoCoordinate> ParseObjectToGeoPosition(ParseObject p) { GeoPosition<GeoCoordinate> g = new GeoPosition<GeoCoordinate>(); g.Timestamp = new DateTimeOffset(p.Get<DateTime>(TIME_STAMP)); ParseGeoPoint pGeoPoint = p.Get<ParseGeoPoint>(LOCATION); g.Location = new GeoCoordinate(); if (pGeoPoint.Latitude != NaNforParse) g.Location.Latitude = pGeoPoint.Latitude; if (pGeoPoint.Longitude != NaNforParse) g.Location.Longitude = pGeoPoint.Longitude; Double pAltitude = p.Get<Double>(ALTITUDE); if (pAltitude != NaNforParse) g.Location.Altitude = pAltitude; Double pHAccuracy = p.Get<Double>(HORIZONTAL_ACCURACY); if (pHAccuracy != NaNforParse) g.Location.HorizontalAccuracy = pHAccuracy; Double pVAccuracy = p.Get<Double>(VERTICAL_ACCURACY); if (pVAccuracy != NaNforParse) g.Location.VerticalAccuracy = pVAccuracy; Double pSpeed = p.Get<Double>(SPEED); if (pSpeed != NaNforParse) g.Location.Speed = pSpeed; Double pCourse = p.Get<Double>(COURSE); if (pCourse != NaNforParse) g.Location.Course = pCourse; return g; }
internal static Position GetPosition(GeoPosition<GeoCoordinate> position) { if (position.Location.IsUnknown) return null; var p = new Position(); p.Accuracy = position.Location.HorizontalAccuracy; p.Longitude = position.Location.Longitude; p.Latitude = position.Location.Latitude; if (!Double.IsNaN(position.Location.VerticalAccuracy) && !Double.IsNaN(position.Location.Altitude)) { p.AltitudeAccuracy = position.Location.VerticalAccuracy; p.Altitude = position.Location.Altitude; } if (!Double.IsNaN(position.Location.Course)) p.Heading = position.Location.Course; if (!Double.IsNaN(position.Location.Speed)) p.Speed = position.Location.Speed; p.Timestamp = position.Timestamp; return p; }
private static void readRecordedData() { String name = "/WazeWP7;component/resources/points.csv"; StreamResourceInfo ri = App.GetResourceStream(new Uri(name, UriKind.Relative)); byte[] buffer = new byte[ri.Stream.Length]; StreamReader sr = new StreamReader(ri.Stream); string s = sr.ReadLine(); while (s != null) { string[] items = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); double longitude = double.Parse(items[0]); double latitude = double.Parse(items[1]); double speed = double.Parse(items[2]); double course = double.Parse(items[3]); DateTime time = DateTime.Parse(items[5]); GeoPosition<GeoCoordinate> position = new GeoPosition<GeoCoordinate>(); position.Location = new GeoCoordinate(); position.Location.Longitude = longitude; position.Location.Latitude = latitude; position.Location.Speed = speed; position.Location.Course = course; position.Timestamp = time; points.Add(position); s = sr.ReadLine(); } }
private void UpdatePosition(GeoPosition<GeoCoordinate> position) { try { int c_pos1 = CibylCallTable.getAddressByName("roadmap_gpsj2me_pos1"); int c_pos2 = CibylCallTable.getAddressByName("roadmap_gpsj2me_pos2"); UIWorker.addUIEvent(c_pos1, (int)(position.Location.Latitude * 1000000), (int)(position.Location.Longitude * 1000000), 0, 0, false); DateTime Now = DateTime.Now.ToUniversalTime(); DateTime baseTime = new DateTime(1970, 1, 1, 0, 0, 0); long currentTimeMillis = (Now - baseTime).Ticks / 10000; UIWorker.addUIEvent(c_pos2, 'A', //(int)(position.Timestamp.Ticks / 1000), //(int)DateTime.Now.Ticks / 10000 / 1000, (int)currentTimeMillis / 1000, (int)(position.Location.Speed * 2), // Convert to ~knots (int)position.Location.Course, false); if (meOnMapMenuItem != null) { //meOnMapMenuItem.CallCallback(); } } catch (Exception ex) { Logger.log("Exception in do_async_connect_cb: " + ex); } }
public bool IsInside(GeoPosition position) { return GreatArc.Distance(_center, position) <= _radius; }
public GeoCoordinateWatcher(GeoPositionAccuracy desiredAccuracy) { DesiredAccuracy = desiredAccuracy; Status = GeoPositionStatus.Initializing; Position = new GeoPosition<GeoCoordinate>(DateTimeOffset.Now, InitialPosition); }
private void ProcessPosition(GeoPosition<GeoCoordinate> position) { if (position == null || position.Location == null || position.Location.IsUnknown) { return; } // Stores the new valid position. DeviceLocation = position.Location; // Uses the location's course if the compass is not enabled. if (!Compass.IsSupported) { DeviceHeading = position.Location.Course; } }
private void ChangeStatusWithEvent(GeoPositionStatus status, GeoCoordinate currentLocation) { Position = new GeoPosition<GeoCoordinate>(DateTimeOffset.Now, currentLocation); ChangeStatusWithEvent(status); if (PositionChanged != null) { PositionChanged(this, new GeoPositionChangedEventArgs<GeoCoordinate>(Position)); } }
public GeoPosition<GeoCoordinate> GetCurrentLocation() { GeoCoordinateWatcher gcw = new GeoCoordinateWatcher(); GeoPosition<GeoCoordinate> currentCoordinate = new GeoPosition<GeoCoordinate>(); currentCoordinate.Location = new GeoCoordinate(47.627903, -122.143185); var CurrentLocation = gcw.Position; if (!CurrentLocation.Location.IsUnknown) { currentCoordinate.Location.Latitude = CurrentLocation.Location.Latitude; currentCoordinate.Location.Longitude = CurrentLocation.Location.Longitude; } return currentCoordinate; }
public Circle(string id, GeoPosition center, Length radius) { _id = id; _center = center; _radius = radius; }
/// <summary> /// Processed the watcher <see cref="GeoCoordinateWatcher.PositionChanged" /> event. /// </summary> /// <param name="e">The <see cref="GeoPositionChangedEventArgs{GeoCoordinate}" /> instance containing the event data.</param> protected override void OnPositionChanged(GeoPositionChangedEventArgs<GeoCoordinate> e) { _position = e.Position; if (_reportInterval == 0) { RaisePositionChangedEvent(); } }
private void TimerCallbackEmulator(object state) { if (point_index >= points.Count - 1) point_index = 0; last_position = points[point_index]; last_update_time = DateTime.UtcNow; UpdatePosition(points[point_index++]); }
private void RaisePositionChangedEvent() { var eventHandler = PositionChanged; var position = _position; if (eventHandler != null && position != null) { _position = null; var locationServicePosition = position.ToLocationServicePosition(); eventHandler(this, new LocationServicePositionChangedEventArgs(locationServicePosition)); } }
public void gps_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) { UpdatePosition(e.Position); last_update_time = DateTime.UtcNow; last_position = e.Position; }
private void WatcherOnPositionChanged (object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) { if (e.Position.Location.IsUnknown) return; bool isRecent = (e.Position.Timestamp - this.start).TotalMilliseconds < this.timeout; if (e.Position.Location.HorizontalAccuracy <= this.desiredAccuracy && isRecent) this.tcs.TrySetResult (Geolocator.GetPosition (e.Position)); if (this.bestPosition == null || e.Position.Location.HorizontalAccuracy < this.bestPosition.Location.HorizontalAccuracy) this.bestPosition = e.Position; }
protected bool Equals(GeoPosition other) { return Longitude.Equals(other.Longitude) && Latitude.Equals(other.Latitude); }
void RefreshPosition(GeoPosition<GeoCoordinate> position) { _currLatitude = new Degree(position.Location.Latitude); _currLongitude = new Degree(position.Location.Longitude); }
public int SaveFile(GeoPosition<GeoCoordinate> Position = null) { if (Position == null) { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); watcher.Start(); Position = watcher.Position; } var fileName = CurrentFileName(); var tempFileName = "record.gpx.temp"; var count = 0; bool firstRun = true; IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication(); if (isStore.FileExists(tempFileName)) { isStore.DeleteFile(tempFileName); } if (isStore.FileExists(fileName)) { firstRun = false; isStore.MoveFile(fileName, tempFileName); } using (IsolatedStorageFileStream input = new IsolatedStorageFileStream(tempFileName, System.IO.FileMode.OpenOrCreate, FileAccess.Read, isStore)) using (IsolatedStorageFileStream output = new IsolatedStorageFileStream(fileName, System.IO.FileMode.OpenOrCreate, FileAccess.Write, isStore)) using (GpxWriter writer = new GpxWriter(output)) { GpxWayPoint last = null; if (!firstRun) { using (GpxReader reader = new GpxReader(input)) { while (reader.Read()) { switch (reader.ObjectType) { case GpxObjectType.WayPoint: count++; writer.WriteWayPoint(reader.WayPoint); last = reader.WayPoint; break; } } } } IsolatedStorageSettings.ApplicationSettings["LastLocation"] = last; IsolatedStorageSettings.ApplicationSettings.Save(); if (double.IsNaN(Position.Location.Latitude) || double.IsNaN(Position.Location.Longitude)) { return count; } if (last == null || last.Time.ToString() != Position.Timestamp.UtcDateTime.ToString()) { writer.WriteWayPoint(new GpxWayPoint { Latitude = Position.Location.Latitude, Longitude = Position.Location.Longitude, Elevation = Position.Location.Altitude, Time = Position.Timestamp.UtcDateTime, }); count++; } } return count; }
private void ParseCGA(NmeaMessage message) { GeoPosition position = new GeoPosition(); double longitude = 0, latitude = 0; var f = (NmeaField) message.Fields[GGA.FieldIds.PositionFixIndicator]; if ((f != null) && f.HasValue) { position.PositionFixIndicator = f.GetInt(position.PositionFixIndicator); } f = (NmeaField) message.Fields[GGA.FieldIds.X]; if ((f != null) && f.HasValue) { longitude = f.GetDouble(_position.Coordinate.Longitude); } f = (NmeaField) message.Fields[GGA.FieldIds.Y]; if ((f != null) && f.HasValue) { latitude = f.GetDouble(_position.Coordinate.Latitude); } f = (NmeaField) message.Fields[GGA.FieldIds.Utc]; if ((f != null) && f.HasValue) { position.Time = f.GetTime(position.Time); } f = (NmeaField) message.Fields[GGA.FieldIds.Satelites]; if ((f != null) && f.HasValue) { position.Satelites = f.GetInt(position.Satelites); } f = (NmeaField) message.Fields[GGA.FieldIds.Hdop]; if ((f != null) && f.HasValue) { position.Hdop = f.GetInt(position.Hdop); } _position.Coordinate = new GeoCoordinate((float)latitude, (float)longitude); }