by Bar Zohan
16. April 2010 23:32
If you have a mobile device that has an entegrated gps and uses windows mobile as operating system you can access the gps data very simply using a wrapper library that handles gps operations.
First download this wrapper library.
Microsoft.WindowsMobile.Samples.Location.rar (7.19 kb)
Add a reference to it inside your project. And a using line at the top of your code to easily access the objects inside the namespace.
using Microsoft.WindowsMobile.Samples.Location;
Then initialize a gps object.
Gps gps = new Gps();
if (!gps.Opened)
{
gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
gps.Open();
}
And inside event handlers you can get any gps related information like count of satellies in view, latitude and longitude, heading, altitude from sea level, altitude from elipsoid.
private void gps_LocationChanged(object sender, LocationChangedEventArgs args)
{
GpsPosition position = args.Position;
double latitude = position.Latitude;
double longitude = position.Longitude;
float heading = position.Heading;
int satelliteCount = position.SatellitesInViewCount;
}
private void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
{
GpsDeviceState device = args.DeviceState;
string deviceName = device.FriendlyName;
string deviceState = device.DeviceState.ToString();
string serviceState = device.ServiceState.ToString();
}