WM--GPS Development

Source: Internet
Author: User
Tags thread

A few days ago, a friend asked me to write him a GPS program, to learn latitude coordinates, and convert it into a Gaussian rectangular coordinate. It took some time to make a small program for him.

Later summed up, think of, many online friends will ask about the development of GPs some things. I will explain my procedure here first, then summarize the relevant experience and personal opinion.

At present, in some mobile devices, all provide GPS function, the device needs a receiver, used to receive GPS signals. (similar to the way GPRS works). Once the GPS is activated, it will automatically connect with the satellite, receive the signal, calculate the position through the algorithm, and then output in the format of NMEA data. GPS Receiver is a device that receives satellite signals and converts them into NMEA data.

The development of GPS has 3 options:

1. Direct use of serial port to connect GPS receiver

2. GPS Intermediate Driver

2. Using a Third-party class library (currently OPENNETCF provides the corresponding class library)

At present, WM5.0 above system, have built-in GPS intermediate Driver. Through it, we can easily by way of GPS data.

About the GPS article can refer to:

1. The. NET [Windows Mobile Applications]-day 03:gps Compass (GPS Compass)

2. Data analysis of GPs NMEA under the. NET Compact Framework

Although GPS intermediate driver provides us with very fast access to GPS information, but at the same time there are some drawbacks.

So let me explain how I use GPS in this project.

I use GPS intermediate Driver, which can be developed quickly, and MS also provides powerful examples to facilitate our use.

There is a GPS project under Microsoft's WM SDK installation directory. (Windows Mobile 6 Sdk\samples\pocketpc\cs\gps)

In the demo

GPS.cs: Encapsulates the GPS operation class, such as open (), close (), Connect (). Can be used very quickly.

GpsDeviceState.cs: Used to obtain status information of current GPS devices.

GpsPosition.cs: Every time GPS data is obtained, it will be placed in the class.

LocationChangedEventArgs.cs: Once the position is changed, the new gpsposition can be obtained.

public void Open()
{
    if (!Opened)
    {
         // create handles for GPS events
         newLocationHandle = CreateEvent(IntPtr.Zero, 0, 0, null);
         deviceStateChangedHandle = CreateEvent(IntPtr.Zero, 0, 0, null);
         stopHandle = CreateEvent(IntPtr.Zero, 0, 0, null);

         gpsHandle = GPSOpenDevice(newLocationHandle, deviceStateChangedHandle, null, 0);

         // if events were hooked up before the device was opened, we'll need
         // to create the gps event thread.
         if (locationChanged != null || deviceStateChanged != null)
         {
             CreateGpsEventThread();
         }
    }
}

By calling CreateEvent, create the handles, and then invoke the Gpsopendevice API, pass handle to the GPS device handle

After getting handle, create a thread to monitor GPS data and device status. By calling the Creategpseventthread method.

private void CreateGpsEventThread()
{
    // we only want to create the thread if we don't have one created already
    // and we have opened the gps device
    if (gpsEventThread == null && gpsHandle != IntPtr.Zero)
    {
        // Create and start thread to listen for GPS events
        gpsEventThread = new System.Threading.Thread(new System.Threading.ThreadStart(WaitForGpsEvents));
        gpsEventThread.Start();
    }
}

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.