public static bool IsPositionValid(GPSPosition position, bool ValidateFix, float MAXDOP) { bool posOk = false; if ((position != null)) { if (position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_UTC_TIME) & position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_HORIZONTAL_DILUTION_OF_PRECISION) & position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_LATITUDE) & position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_LONGITUDE) & (position.fixType >= GPSFixType.XyD | ValidateFix == false)) { if ((MAXDOP >= position.flHorizontalDilutionOfPrecision) | MAXDOP == -1) { posOk = true; } } } return(posOk); }
private void ticking() { try { if (!glbGPS.IsOpen()) { ST("No esta abierto el GPS!!!"); } GPSPosition Position = glbGPS.GetPosition(); if ((Position != null)) { HDOPLabel.Text = Position.flHorizontalDilutionOfPrecision.ToString("0.00"); //ErrorLabel.Text = (Position.flHorizontalDilutionOfPrecision * 6) + " m"; SatelitesLabel.Text = Position.dwSatelliteCount.ToString(); if (Position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_LONGITUDE)) { LongLabel.Text = Position.dblLongitude.ToString("0.0000000"); } else { LongLabel.Text = ""; } if (Position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_LATITUDE)) { LatLabel.Text = Position.dblLatitude.ToString("0.0000000"); } else { LatLabel.Text = ""; } try { if (Position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_UTC_TIME)) { StampLabel.Text = Position.Time.ToString("yyyy/MM/dd HH:mm"); } else { StampLabel.Text = ""; } } catch (Exception ex) { StampLabel.Text = ex.ToString(); //Position.Time.ToString(); } switch (Position.fixType) { case GPSFixType.Unknown: FixTypeLabel.Text = ""; break; case GPSFixType.XyD: FixTypeLabel.Text = "2D"; break; case GPSFixType.XyzD: FixTypeLabel.Text = "3D"; break; } switch (Position.fixQuality) { case GPSFixQuality.DGps: FixTypeLabel.Text += " DGPS"; break; case GPSFixQuality.Gps: FixTypeLabel.Text += " GPS"; break; } lastPosition = Position; if (glbGPS.IsPositionValid(Position)) { pnlFixed.BackColor = Color.LimeGreen; StatusLabel.BackColor = Color.LimeGreen; ST("Posicion obtenida"); gotFix = true; btAceptar.Enabled = true; Time = DateTime.Now; // timer1.Enabled = false; } else { pnlFixed.BackColor = Color.OrangeRed; StatusLabel.BackColor = Color.OrangeRed; if (!odd) { odd = true; ST("Esperando posición"); } else { odd = false; ST("Buscando satélites"); } gotFix = false; btAceptar.Enabled = false; } } else { //GrabarButton.Enabled = False pnlFixed.BackColor = Color.Red; } } catch (Exception ex) { ST(ex.Message.ToString()); } }