0% found this document useful (0 votes)
55 views

Code

Uploaded by

trongly
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Code

Uploaded by

trongly
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Samples.Location;
using System.Reflection;
using System.Net;
using System.IO;

namespace ShowGPS
{
public partial class Form1 : Form
{
private Gps gps;
public Form1()
{
InitializeComponent();
gps = new Gps();
}

private void menuItem1_Click(object sender, EventArgs e)


{
if (!gps.Opened)
{
gps.DeviceStateChanged += new
DeviceStateChangedEventHandler(gps_DeviceStateChanged);
gps.LocationChanged += new
LocationChangedEventHandler(gps_LocationChanged);
gps.Open();
}

else
{
gps.DeviceStateChanged -= gps_DeviceStateChanged;
gps.LocationChanged -= gps_LocationChanged;
gps.Close();
tbGPSDevice.Text = "";
tbGPSDeviceState.Text = "";
tbGPSServiceState.Text = "";
tbHeading.Text = "";
tbLatitude.Text = "";
tbLongitude.Text = "";
tbSatellites.Text = "";
}
menuItem1.Text = gps.Opened ? "GPS Off" : "GPS On";

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

void gps_LocationChanged(object sender, LocationChangedEventArgs args)


{
ControlUpdater cu = UpdateControl;

GpsPosition position = args.Position;

if (position.LatitudeValid)
Invoke(cu, tbLatitude, position.Latitude.ToString());
if (position.LongitudeValid)
Invoke(cu, tbLongitude, position.Longitude.ToString());
if (position.HeadingValid)
Invoke(cu, tbHeading, position.Heading.ToString());
if (position.SatellitesInViewCountValid)
Invoke(cu, tbSatellites,
position.SatellitesInViewCount.ToString());
}

void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs


args)
{
ControlUpdater cu = UpdateControl;

GpsDeviceState device = args.DeviceState;

Invoke(cu, tbGPSDevice, device.FriendlyName);


Invoke(cu, tbGPSDeviceState, device.DeviceState.ToString());
Invoke(cu, tbGPSServiceState, device.ServiceState.ToString());
}

private delegate void ControlUpdater(Control c, string s);

private void UpdateControl(Control c, string s)


{
c.Text = s;
}

private void Form1_Closing(object sender, CancelEventArgs e)


{
if (gps.Opened)
{
gps.DeviceStateChanged -= gps_DeviceStateChanged;
gps.LocationChanged -= gps_LocationChanged;

gps.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
gps.DeviceStateChanged += new
DeviceStateChangedEventHandler(gps_DeviceStateChanged);
gps.LocationChanged += new
LocationChangedEventHandler(gps_LocationChanged);
gps.Open();
}

private void timer1_Tick(object sender, EventArgs e)


{
webBrowser1.Url = new
Uri("http://tnak1988.0fees.net/gps/post.php?latitude=" + tbLatitude.Text +
"&longitude=" + tbLongitude.Text);

private void menuItem3_Click(object sender, EventArgs e)


{
timer1.Enabled = true;
}

private void menuItem4_Click(object sender, EventArgs e)


{
gps.DeviceStateChanged -= gps_DeviceStateChanged;
gps.LocationChanged -= gps_LocationChanged;
gps.Close();
Application.Exit();
}
}
}

You might also like