30 Days of. NET [Windows Mobile Applications]-Day 03: GPS Compass)

Source: Internet
Author: User

For the original article, see Day 03: GPS Compass

Requirement

Use GPS information to display the compass.

Implementation

The GPS compass displays the azimuth of the current position on the UI. This information is included in the NMEA output by the GPS receiver. The eighth field stored in gprs mc.

$ Gprs mc, 015834, A, 3749.8448, S, 14459.6697, E, 000.0, 136.8, 120908,011.7, E * 63

In the preceding example, 136.8 is the azimuth. Based on NMEA analysis, I wrote an article about GPS NMEA data analysis under. NET Compact Framework.

The author proposes that there are three options for GPS development: 1. Use Serial Port to connect to GPS receiver directly. 2. Use OpenNETCF GPS Library. 3. Use GPS Intermediate Driver.
The author finally chose the GPS Intermediate Driver, which supports Windows Mobile 5 and later systems. MS claims that the GPS Intermediate Driver can shield all hardware differences. To be honest, blocking all hardware differences means that the Library only supports General NMEA and the vendor's NMEA cannot be parsed. There are advantages and disadvantages in everything. The technical selection mainly depends on the needs. The requirement for this compass is relatively simple. It only needs to retrieve the azimuth information and use the GPS Intermediate Driver to improve the development efficiency.

To develop the GPS Intermediate Driver, refer to the example code C: \ Program Files \ Windows Mobile 6 SDK \ Samples \ PocketPC \ CS \ GPS in Windows Mobile 6. MS encapsulates the GPS Intermediate Driver into Microsoft. WindowsMobile. Samples. Location for Compatct Framework development. We only need to use Microsoft. WindowsMobile. Samples. Location.

GpsDeviceState device = null;
GpsPosition position = null;
Gps gps = new Gps ();

Private void Form1_Load (object sender, System. EventArgs e)
{
Gps. DeviceStateChanged + = new DeviceStateChangedEventHandler (gps_DeviceStateChanged );
Gps. LocationChanged + = new LocationChangedEventHandler (gps_LocationChanged );
}

Private void startGpsMenuItem_Click (object sender, EventArgs e)
{
If (! Gps. Opened)
{
Gps. Open ();
}
}

Private void stopGpsMenuItem_Click (object sender, EventArgs e)
{
If (gps. Opened)
{
Gps. Close ();
}
}

The above is the core code using Microsoft. WindowsMobile. Samples. Location. GpsDeviceState device defines the status of the GPS device. For the specific status of the device, refer to the enum definition in GpsDeviceState. cs.

Public enum GpsServiceState: int
{
Off = 0,
On = 1,
StartingUp = 2,
ShuttingDown = 3,
Unloading = 4,
Uninitialized = 5,
Unknown =-1
}

GpsPosition position defines the location information. In fact, this class is a big and comprehensive class, and all the information that can be analyzed by General NMEA is put in this class.

The class chart definition shows that we can not only obtain the azimuth information, but also obtain the latitude and longitude, altitude, UTC time, speed, satellite status, error value, and so on in this class.

Gps object indicates a Gps device, gps. Open (); to Open the device, start to accept GPS information, gps. Close (); to Close the device. Gps. DeviceStateChanged + = new DeviceStateChangedEventHandler (gps_DeviceStateChanged); and gps. LocationChanged + = new LocationChangedEventHandler (gps_LocationChanged. According to the GpsPosition class definition, when the position changes, that is, when the callback gps_LocationChanged, you can retrieve the longitude and latitude, altitude, and other information. Therefore, you only need to subscribe to this message to complete almost all GPS development.

Use a false GPS (FakeGPS) device to test the program

The author provides a test method that allows devices without GPS Referer to perform tests. FakeGPS can be found in C: \ Program Files \ Windows Mobile 6 SDK \ Tools \ GPS. For more information about FakeGPS, see A Windows Mobile GPS Application Sample-Using Fake GPS.

Set Share Folder.

Install FakeGPS. CAB.

Configure FakeGPS.


Use FakeGPS to test GpsCompass. Please test it in Window Mobile 6 Professional. I test it in Window Mobile 6 Classic. Turning on the GPS device fails.

 

Installer: GpsCompass. cab

Source code: GpsCompass.zip
 

. NET Compact Framework, WinCE, Windows Mobile Development Series

Jake's Blog in Blog Park-simplified development of wireless life

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.