//set list of active satellites public void setSatellite(GpsPosition position) { if (position.GetSatellitesInSolution() == null) satelliteList = new List <Satellite>(); else satelliteList =position.GetSatellitesInView().ToList(); }
//add track data to database (to gpsData table) and clear list of position public void addTrackData(GPS.Position <GpsPosition> positionList) { GpsPosition[] positionArray =new GpsPosition[positionList.Count]; positionList.CopyTo(positionArray, 0); positionList.Clear(); StringBuilder query = new StringBuilder(); try { foreach (GpsPosition pos in positionArray) { query.Append("INSERT INTO gpsData ('trackId', 'longitude', 'latitude', 'altitude', 'fix') VALUES ("); query.Append(trackId + ", '"); query.Append(pos.Longitude + "', '"); query.Append(pos.Latitude + "', '"); query.Append(pos.SeaLevelAltitude + "', '"); query.Append((int)pos.PositionDilutionOfPrecision + "');"); } createSqliteConn(); executeQuery(query, false); closeSqliteConn(); } catch (SQLiteException sqliteEx) { MessageBox.Show("exception "+ sqliteEx.Message); } }
protected void gps_LocationChanged(object sender, LocationChangedEventArgs args) { position = args.Position; // call the UpdateData method via the updateDataHandler so that we // update the UI on the UI thread Invoke(updateDataHandler); }
/// <summary> /// Get the position reported by the GPS receiver that is no older than /// the maxAge passed in /// </summary> /// <param name="maxAge">Max age of the gps position data that you want back. /// If there is no data within the required age, null is returned. /// if maxAge == TimeSpan.Zero, then the age of the data is ignored</param> /// <returns>GpsPosition class with all the position details</returns> public GpsPosition GetPosition(TimeSpan maxAge) { GpsPosition gpsPosition = null; if (Opened) { // allocate the necessary memory on the native side. We have a class (GpsPosition) that // has the same memory layout as its native counterpart IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition))); // fill in the required fields gpsPosition = new GpsPosition(); gpsPosition.dwVersion = 1; gpsPosition.dwSize = Marshal.SizeOf(typeof(GpsPosition)); // Marshal our data to the native pointer we allocated. Marshal.StructureToPtr(gpsPosition, ptr, false); // call native method passing in our native buffer int result = GPSGetPosition(gpsHandle, ptr, 500000, 0); if (result == 0) { // native call succeeded, marshal native data to our managed data gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition)); if (maxAge != TimeSpan.Zero) { // check to see if the data is recent enough. if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time) { gpsPosition = null; } } } // free our native memory Utils.LocalFree(ptr); } return(gpsPosition); }
//update data in form components public void updateForm(GpsPosition position) { if(mapStatus == MapStatus.TABS_VISIBLE && gpsStatus==GpsStatus.GPS_OPEN) Invoke((UpdateDelegate)delegate() { if (position.LatitudeValid) { lLatitudeDegVal.Text = position.LatitudeInDegreesMinutesSeconds.Degrees.ToString() + "°"; lLatitudeMinVal.Text = position.LatitudeInDegreesMinutesSeconds.Minutes.ToString() + "'"; lLatitudeSekVal.Text = position.LatitudeInDegreesMinutesSeconds.Seconds.ToString() + "\""; } if (position.LongitudeValid) { lLongitudeDegVal.Text = position.LongitudeInDegreesMinutesSeconds.Degrees.ToString() + "°"; lLongitudeMinVal.Text = position.LongitudeInDegreesMinutesSeconds.Minutes.ToString() + "'"; lLongitudeSekVal.Text = position.LongitudeInDegreesMinutesSeconds.Seconds.ToString() + "\""; } if (position.SeaLevelAltitudeValid) lAltitudeVal.Text = position.SeaLevelAltitude.ToString(); if (position.TimeValid) { lTimeHVal.Text = position.Time.TimeOfDay.Hours.ToString() +"h"; lTimeMVal.Text = position.Time.TimeOfDay.Minutes.ToString() +"m"; lTimeSVal.Text = position.Time.TimeOfDay.Seconds.ToString() +"s"; lDateVal.Text = position.Time.ToShortDateString(); } if (position.SpeedValid) lSpeedVal.Text = knotToKm(position.Speed).ToString(); lLatitudeDegVal.Invalidate(); lLatitudeMinVal.Invalidate(); lLatitudeSekVal.Invalidate(); lLongitudeDegVal.Invalidate(); lLongitudeMinVal.Invalidate(); lLongitudeSekVal.Invalidate(); lAltitudeVal.Invalidate(); lTimeHVal.Invalidate(); lTimeMVal.Invalidate(); lTimeSVal.Invalidate(); lDateVal.Invalidate(); lSpeedVal.Invalidate(); satelliteSignalVisualization1.Invalidate(); satelliteSignalVisualization1.Update(); }); }
public LocationChangedEventArgs(GpsPosition position) { this.position = position; }
public LocationChangedEventArgs(GpsPosition position) { this.position = position; }
private void position2XMLFile(GpsPosition position) { DateTime dateTime1; using (StreamWriter streamWriter1 = new StreamWriter("bcPosition.xml")) { streamWriter1.WriteLine("<?xml version0x03d\"1.0\"?>"); streamWriter1.WriteLine("<position>"); streamWriter1.Write("<latitude>"); streamWriter1.Write(position.Latitude); streamWriter1.WriteLine("</latitude>"); streamWriter1.Write("<longitude>"); streamWriter1.Write(position.Longitude); streamWriter1.WriteLine("</longitude>"); streamWriter1.Write("<speed>"); streamWriter1.Write(position.Speed); streamWriter1.WriteLine("</speed>"); streamWriter1.Write("<cog>"); streamWriter1.Write(position.Heading); streamWriter1.WriteLine("</cog>"); streamWriter1.Write("<elev>"); streamWriter1.Write(position.SeaLevelAltitude); streamWriter1.WriteLine("</elev>"); streamWriter1.Write("<satsolution>"); streamWriter1.Write(position.SatelliteCount); streamWriter1.WriteLine("</satsolution>"); streamWriter1.Write("<ticks>"); dateTime1 = position.Time; streamWriter1.Write(dateTime1.Ticks); streamWriter1.WriteLine("</ticks>"); streamWriter1.Write("<jsdate>"); streamWriter1.Write(((dateTime1 = position.Time).ToString("MM\'/\'dd\'/\'yyyy hh:mm:ss") + " UTC+0000")); streamWriter1.WriteLine("</jsdate>"); streamWriter1.Write("<isodate>"); streamWriter1.Write(((dateTime1 = position.Time).ToString("s") + "Z")); streamWriter1.WriteLine("</isodate>"); streamWriter1.WriteLine("</position>"); } }
protected void gps_LocationChanged(object sender, LocationChangedEventArgs args) { position = args.Position; // call the UpdateData method via the updateDataHandler so that we // update the UI on the UI thread try { BeginInvoke(updateDataHandler); } catch (NullReferenceException ) { } }
/// <summary> /// Get the position reported by the GPS receiver that is no older than /// the maxAge passed in /// </summary> /// <param name="maxAge">Max age of the gps position data that you want back. /// If there is no data within the required age, null is returned. /// if maxAge == TimeSpan.Zero, then the age of the data is ignored</param> /// <returns>GpsPosition class with all the position details</returns> public GpsPosition GetPosition(TimeSpan maxAge) { GpsPosition gpsPosition = null; if (Opened) { // allocate the necessary memory on the native side. We have a class (GpsPosition) that // has the same memory layout as its native counterpart IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition))); // fill in the required fields gpsPosition = new GpsPosition(); gpsPosition.dwVersion = 1; gpsPosition.dwSize = Marshal.SizeOf(typeof(GpsPosition)); // Marshal our data to the native pointer we allocated. Marshal.StructureToPtr(gpsPosition, ptr, false); // call native method passing in our native buffer int result = GPSGetPosition(gpsHandle, ptr, 500000, 0); if (result == 0) { // native call succeeded, marshal native data to our managed data gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition)); if (maxAge != TimeSpan.Zero) { // check to see if the data is recent enough. if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time) { gpsPosition = null; } } } // free our native memory Utils.LocalFree(ptr); } return gpsPosition; }
//retrive gps position to save into database and display in parent form public void retrivePosition(GpsPosition position) { try { //if satellite info is avaliable if (position.SatellitesInSolutionValid && position.SatelliteCountValid && position.SatellitesInViewValid) { if (position.PositionDilutionOfPrecisionValid && position.PositionDilutionOfPrecision<7) { //add position to position list parentForm.gpsPositionList.Add(position); } //set satellite data in satView satView.setSatellite(position); //display on form components parentForm.updateForm(position); } }catch (Exception ex) { MessageBox.Show("mess retr" + ex.Message); } }
static void gps_LocationChanged(object sender, LocationChangedEventArgs args) { position = args.Position; }
void _gps_LocationChanged(object sender, LocationChangedEventArgs args) { GpsPosition = args.Position; PrintLn("GPS Location Changed: " + ToString(GpsPosition)); }
string ToString(GpsPosition pos) { return "" + (pos.LatitudeValid ? "" : "(INVALID)") + pos.Latitude.ToString("F6") + "," + (pos.LongitudeValid ? "" : "(INVALID)") + pos.Longitude.ToString("F6"); }
public void pollGPS() { gps = new Gps(); gps.Open(); gpsPosition = gps.GetPosition(); //while (!gpsPosition.LatitudeValid || !gpsPosition.LatitudeValid) //Thread.Sleep(500); gps.Close(); latitude = gpsPosition.Latitude; longitude = gpsPosition.Longitude; }