⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm_gpsdataget.cs

📁 PDA GPS 开发源码 基于ESRI.ArcGIS.Mobile实现在手持设备上的地图浏览。
💻 CS
字号:
// Copyright 2006 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See use restrictions at /arcgis/developerkit/userestrictions.
// 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Mobile.Gps;

namespace MobileGPS
{
  public partial class Frm_GpsDataGet : Form
  {
    GpsEventArgs m_gpsea = null;

    public Frm_GpsDataGet()
    {
      InitializeComponent();
    }

    private void DisplayPosition()
    {
      if (m_gpsea == null)
        return;

      labelLatitude.Text = m_gpsea.Latitude.ToString();
      labelLongitude.Text = m_gpsea.Longitude.ToString();
      labelAltitude.Text = m_gpsea.Altitude.ToString();

      if (m_gpsea.FixStatus.ToString()=="0") 
      {
        labelFixMode.Text ="不可定位";
      }
      else
      {
        labelFixMode.Text ="可定位";
      }


      labelPDOP.Text = m_gpsea.Pdop.ToString();
      labelVDOP.Text = m_gpsea.Vdop.ToString();
      labelHDOP.Text = m_gpsea.Hdop.ToString();

      if (m_gpsea.Pdop <= 4)
      {
          labelJd.Text = "定位精度高";
      };

      if (m_gpsea.Pdop>4&&m_gpsea.Pdop<7)
      {
          labelJd.Text = "定位精度一般";
      };
      if (m_gpsea.Pdop>=7)
      {
          labelJd.Text = "定位精度差";
      };
      


      DateTime utc = DateTime.MinValue;
      utc = m_gpsea.Time;

      labelTimeLocal.Text = utc.ToLocalTime().ToString();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      DisplayPosition();
      DisplaySatellites();
    }

    private void serialPortGpsConnection1_GpsChanged(object sender, GpsEventArgs e)
    {
      m_gpsea = e;
    }

    private void DisplaySatellites()
    {

      Pen circlePen = new Pen(System.Drawing.Color.DarkBlue, 1);

      Graphics g = picSats.CreateGraphics();

      int centerX = picSats.Width / 2;
      int centerY = picSats.Height / 2;

      double maxRadius = (Math.Min(picSats.Height, picSats.Width) - 20) / 2;

      //draw circles
      double[] elevations = new double[] { 0, Math.PI / 2, Math.PI / 3, Math.PI / 6 };

      foreach (double elevation in elevations)
      {
        double radius = (double)System.Math.Cos(elevation) * maxRadius;
        g.DrawEllipse(circlePen, (int)(centerX - radius), (int)(centerY - radius), (int)(2 * radius), (int)(2 * radius));
      }
      //90 degrees elevation reticule
      g.DrawLine(circlePen,(centerX - 3), centerY,(centerX + 3), centerY);
      g.DrawLine(circlePen,centerX, (centerY - 3), centerX, (centerY + 3));

      Pen satPen = new Pen(System.Drawing.Color.Green, 4);
 
			listSatellites.Items.Clear();

      try
      {
        foreach (Satellite sat in m_gpsea.GetSatellites())
        {
          if (null == sat) return;

          ListViewItem lvItem = new ListViewItem
            (
              new string[] 
              {
                sat.Id.ToString(),
                sat.Elevation.ToString(),
                sat.Azimuth.ToString(),
                sat.Snr.ToString(),
              }
            );

          listSatellites.Items.Add(lvItem);

          //draw satellites
          double h = (double)System.Math.Cos((sat.Elevation * Math.PI) / 180) * maxRadius;

          int satX = (int)(centerX + h * Math.Sin((sat.Azimuth * Math.PI) / 180));
          int satY = (int)(centerY - h * Math.Cos((sat.Azimuth * Math.PI) / 180));

          g.DrawRectangle(satPen, satX, satY, 4, 4);
          g.DrawString(sat.Id.ToString(), new Font("Verdana", 8, FontStyle.Regular), new System.Drawing.SolidBrush(Color.Black), (satX + 5), (satY + 5));
        }
      }
      catch
      {
        return;
      }
    }


    private void menuItem1_Click(object sender, EventArgs e)
    {
      
    }

    private void menuItem2_Click(object sender, EventArgs e)
    {
    
    }

    private void Form1_Load(object sender, EventArgs e)
    {
       
       
        menuItem5.Enabled = false; //disc gps softkey
    }

    private void map1_ExtentChanged(object sender, EventArgs e)
    {
     if (!map1.IsValid || !mapCache1.IsSynchronizationProtocolValid)
       return;
      mapCache1.GetDataAsync(map1, true, null);
    }

      private void menuItem4_Click(object sender, EventArgs e)
      {
          //softmenu1 gps connect
          //serialPortGpsConnection1.PortName = "COM1"; //harcode...

          serialPortGpsConnection1.Open();
          timer1.Enabled = true;
          menuItem4.Enabled = false;
          menuItem5.Enabled = true;
      }

      private void menuItem5_Click(object sender, EventArgs e)
      {
          //softmenu2 gps disconnect
          timer1.Enabled = false;
          serialPortGpsConnection1.Close();
          menuItem5.Enabled = false;
          menuItem4.Enabled = true;
      }

      private void menuItem6_Click(object sender, EventArgs e)
      {
          Application.Exit();
      }

      private void newMenuItemMenuItem_Click(object sender, EventArgs e)
      {

      }

      private void dataGrid1_Click(object sender, EventArgs e)
      {

      }

      private void menuItem1_Click_1(object sender, EventArgs e)
      {
          if (!mapCache1.IsValid)
          {
              MessageBox.Show("Map Cache is not valid!");
              return;
          }
          try
          {
              mapCache1.Open();
          }
          catch(System.Exception ee)
          {
              string err = ee.ToString();
              MessageBox.Show("Cannot open map cache");
          }

      }

      private void menuItem2_Click_1(object sender, EventArgs e)
      {

      }

      private void contextMenu1_Popup(object sender, EventArgs e)
      {

      }

      private void menuItem8_Click(object sender, EventArgs e)
      {
          map1.CurrentMapAction =zoomInMapAction1;
      }

      private void menuItem9_Click(object sender, EventArgs e)
      {
          map1.CurrentMapAction = zoomOutMapAction1;   
      }

      private void menuItem10_Click(object sender, EventArgs e)
      {
          map1.CurrentMapAction = panMapAction1;
      }

      private void menuItem7_Click(object sender, EventArgs e)
      {

      }

      private void menuItem11_Click(object sender, EventArgs e)
      {
          map1.CurrentMapAction = selectionMapAction1;
      }

  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -