如何撰寫微軟手機的 GPS 衛星接收器程式

作品

書籍

課程

程式集

小說集

論文集

散文集

影片集

編輯雜誌

程式人

電子書

JavaScript

計算語言學

微積分

Blender 動畫

C# 語言

系統程式

高等 C 語言

Java

Android

Verilog

Wikidot

R 統計軟體

機率統計

計算機數學

組合語言

人工智慧

開放原始碼

網路資源運用

計算機結構

相關訊息

常用工具

友站連結

在家教育

RSS

最新修改

網頁列表

簡體版

English

專案程式下載 GpsWatcher.zip

簡介

GpsWatcher.jpg

Gps 衛星接收器的畫面

using System;
using System.IO.Ports;
using System.Windows.Forms;
using System.Data;
using System.Text.RegularExpressions;
using System.IO;
using Microsoft.WindowsMobile.Samples.Location;

namespace ccc.gps
{
    public partial class FormGps : Form
    {
        Gps gps = new Gps();
        private EventHandler locationChangedHandler, deviceStateChangedHandler;

        public FormGps()
        {
            InitializeComponent();
        }

        private void FormGps_Load(object sender, EventArgs e)
        {
            locationChangedHandler = new EventHandler(locationChanged);
            deviceStateChangedHandler = new EventHandler(deviceStateChanged);
            gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
            gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
        }

        private void buttonGetData_Click(object sender, EventArgs e)
        {
            listViewGps.Items.Clear();
            if (!gps.Opened) gps.Open();
            buttonGetData.Enabled = false;
            buttonStopGetData.Enabled = true;
        }

        private void buttonStopGetData_Click(object sender, EventArgs e)
        {
            if (gps.Opened) gps.Close();
            buttonGetData.Enabled = true;
            buttonStopGetData.Enabled = false;
        }

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

        GpsDeviceState deviceState;
        void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
        {
            deviceState = args.DeviceState;
            Invoke(deviceStateChangedHandler);
        }

        void deviceStateChanged(object sender, System.EventArgs args)
        {
        }

        int counter = 0;
        void locationChanged(object sender, System.EventArgs args)
        {
            if (gps.Opened && position != null)    {
                if (position.LatitudeValid && position.LongitudeValid && position.SatelliteCountValid && position.TimeValid)
                {
                    counter++;
                    ListViewItem item = new ListViewItem();
                    item.Text = counter + "";
                    item.SubItems.Add(String.Format("{0:F5}", position.Longitude));
                    item.SubItems.Add(String.Format("{0:F5}", position.Latitude));
                    item.SubItems.Add(String.Format("{0}", position.SatelliteCount));
                    listViewGps.Items.Insert(0, item);
                    if (listViewGps.Items.Count > 15)
                        listViewGps.Items.RemoveAt(15);
                }
            }
        }

        private void menuItemExit_Click(object sender, EventArgs e)
        {
            buttonStopGetData_Click(sender, e);
            Close();
        }

        private void FormGps_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            buttonStopGetData_Click(sender, e);
        }
    }
}

Facebook

gps
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License