예제 #1
0
        // This will print current location
        private void button4_Click(object sender, EventArgs e)
        {
            //Here will be code for location

            label1.Text = "Locating.....";
            // Prepare GpsPosition struct
            GpsPosition coordinates = new GpsPosition();

            coordinates.dwVersion = 1;
            coordinates.dwSize    = Marshal.SizeOf(typeof(GpsPosition));


            IntPtr position = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GpsPosition)));

            // Marshal our data to the native pointer we allocated.
            Marshal.StructureToPtr(coordinates, position, false);
            GPSGetPosition(device, position, 10000, 0);

            try
            {
                if (position != IntPtr.Zero)
                {
                    coordinates = (GpsPosition)Marshal.PtrToStructure(position, typeof(GpsPosition));

                    label1.Text = "Position: " + coordinates.Latitude + ","
                                  + coordinates.Longitude;
                }
                else
                {
                    label1.Text = "Position is null!";
                }
            }
            catch (Exception ex)
            {
                label1.Text = ex.Message;
            }
            //
            Marshal.FreeHGlobal(position);
        }
예제 #2
0
파일: Form1.cs 프로젝트: OSLL/geo2tag-web
        // This will print current location
        private void button4_Click(object sender, EventArgs e)
        {
            //Here will be code for location

            label1.Text = "Locating.....";
            // Prepare GpsPosition struct
            GpsPosition coordinates = new GpsPosition();
            coordinates.dwVersion = 1;
            coordinates.dwSize = Marshal.SizeOf(typeof(GpsPosition));

            IntPtr position = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GpsPosition)));
            // Marshal our data to the native pointer we allocated.
            Marshal.StructureToPtr(coordinates, position, false);
            GPSGetPosition(device, position, 10000, 0);

            try
            {
                if (position != IntPtr.Zero)
                {

                    coordinates = (GpsPosition)Marshal.PtrToStructure(position, typeof(GpsPosition));

                    label1.Text = "Position: " + coordinates.Latitude + ","
                        + coordinates.Longitude;

                }
                else
                {
                    label1.Text = "Position is null!";
                }
            }
            catch (Exception ex)
            {
                label1.Text = ex.Message;
            }
            //
            Marshal.FreeHGlobal(position);
        }