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

📄 form2.cs

📁 关于windows mobile 平台开发与应用的源代码用到的与GPS连接
💻 CS
字号:
#region Using 指令

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
#endregion

namespace GpsSample
{
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
        //GPS设备状态对象
        GpsDeviceState device = null;
        //GPS位置对象
        GpsPosition position = null;
        //GPS对象
        Gps gps = new Gps();
        public Form2()
        {

            InitializeComponent();

        }


        private void Form1_Load(object sender, EventArgs e)
        {
            gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);

            gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);

        }

        //位置改变时更新坐标数据

        protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            position = args.Position;

        }

        //gps设备状态改变时更新设备的状态

        void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
        {

            device = args.DeviceState;

        }



        //菜单:打开GPS设备

        private void open_gps_Click(object sender, EventArgs e)
        {

            if (!gps.Opened)
            {

                gps.Open();

            }

            open_gps.Enabled = false;

            close_gps.Enabled = true;

        }



        //菜单:关闭GPS设备

        private void close_gps_Click(object sender, EventArgs e)
        {

            if (gps.Opened)
            {

                gps.Close();

            }

            open_gps.Enabled = true;

            close_gps.Enabled = false;

        }





        //菜单:退出

        private void exit_Click(object sender, EventArgs e)
        {

            if (gps.Opened)

                gps.Close();

            Close();

        }





        //获取经纬度坐标值

        private void getdata_Click(object sender, EventArgs e)
        {

            string str;

            if (!gps.Opened)
            {

                str = "GPS设备没有打开,请点击打开GPS菜单后重试!";

                MessageBox.Show(str);

                return;

            }

            if (device == null)
            {

                str = "GPS设备打开错误,请重新插拔GPS卡后重试!";

                MessageBox.Show(str);

                return;

            }

            if (position != null)
            {

                string strJd;       //经度

                string strWd;  //纬度

                strJd = position.DoubleLongtitude.ToString();

                strWd = position.DoubleLatitude.ToString();



                DialogResult result;



                str = "经度:" + strJd + "\n纬度:" + strWd;

                result = MessageBox.Show(str, "当前坐标", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

                if (result == DialogResult.OK)
                {

                    //将经过确认的坐标数据显示到相应的TextBox

                    wd.Text = strWd;

                    jd.Text = strJd;

                    return;

                }

            }

        }
    }
}

⌨️ 快捷键说明

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