1

通过 Windows Mobile 开发,您的 .Net 应用程序可以使用 GPS 中间驱动程序,以确保多个应用程序可以使用 GPS 设备,而一个应用程序不会锁定另一个应用程序。我有一个使用 GPS 中间驱动程序的移动应用程序(.Net Compact Framework),我也有这个应用程序的 Windows 版本,不包括 GPS 功能。现在我需要为运行 Windows 7 并且内置 GPS 接收器的平板电脑构建 GPS 功能。与 GPS 接收器的连接是通过一个 com 端口建立的。

是否有相当于 Windows 的 GPS 中间驱动程序允许我的应用程序使用 GPS 接收器,但不会阻止 GPS 接收器用于在 PC 上运行的其他导航软件?

4

2 回答 2

1

是正确的!GeoFramework 它是一个最好的免费 G​​PS 框架。如果您需要在平面上投影/取消投影坐标,这些类可以帮助您:

public interface IProjector
    {
        PointD Deproject(PointD projectedCoordinate);
        PointD Project(PointD geographicCoordinate);
        PointD Project(Position position);
        PointD Project(Latitude latitude, Longitude longitude);
    }

[StructLayout(LayoutKind.Sequential)]
    public struct PointD : IEquatable<PointD>, IFormattable
    {
        private double _x;
        private double _y;
        public static PointD Empty;
        public PointD(double x, double y)
        {
            this._x = x;
            this._y = y;
        }

        public PointD(PointD p)
        {
            this._x = p.X;
            this._y = p.Y;

        }

        public double X
        {
            get
            {
                return this._x;
            }
            set
            {
                this._x = value;
            }
        }
        public double Y
        {
            get
            {
                return this._y;
            }
            set
            {
                this._y = value;
            }
        }
        public bool IsEmpty
        {
            get
            {
                return this.Equals(Empty);
            }
        }
        public Point ToPoint()
        {
            return new Point((int)this._x, (int)this._y);
        }

        public void Normalize()
        {
            double num = Math.Sqrt((this.X * this.X) + (this.Y * this.Y));
            this.X /= num;
            this.Y /= num;
        }

        public static PointD FromSize(Size size)
        {
            return new PointD((double)size.Width, (double)size.Height);
        }

        public static PointD FromSize(SizeF size)
        {
            return new PointD((double)size.Width, (double)size.Height);
        }

        public static bool operator ==(PointD left, PointD right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(PointD left, PointD right)
        {
            return !left.Equals(right);
        }

        public static PointD operator -(PointD left, PointD right)
        {
            return new PointD(left.X - right.X, left.Y - right.Y);
        }

        public override bool Equals(object obj)
        {
            return ((obj is PointD) && this.Equals((PointD)obj));
        }

        public override int GetHashCode()
        {
            return (this._x.GetHashCode() ^ this._y.GetHashCode());
        }

        public override string ToString()
        {
            return this.ToString("G", CultureInfo.CurrentCulture);
        }

        public bool Equals(PointD other)
        {
            return (this._x.Equals(other.X) && this._y.Equals(other.Y));
        }

        public string ToString(string format, IFormatProvider formatProvider)
        {
            CultureInfo info = (CultureInfo)formatProvider;
            return (this._x.ToString(format, formatProvider) + info.TextInfo.ListSeparator + " " + this._y.ToString(format, formatProvider));
        }

        static PointD()
        {
            Empty = new PointD(0.0, 0.0);
        }
    }

public class Projector : IProjector
    {


        private const double DEGREEStoRADIANS = System.Math.PI / 180;
        private const double RADIANStoDEGREES = 180 / System.Math.PI;

        /* These values represent the equatorial radius of the WGS84 ellipsoid in meters.
         * resulting in projected coordinates which are also in meters
         */
        private const double WGS84SEMIMAJOR = 6378137.0;
        private const double ONEOVERWGS84SEMIMAJOR = 1.0 / WGS84SEMIMAJOR;



        public PointD Deproject(PointD projectedCoordinate)
        {

            .PointD result = new PointD();

            // Calculate the geographic X coordinate (longitude)
            result.X = (float)(projectedCoordinate.X * ONEOVERWGS84SEMIMAJOR / System.Math.Cos(0) * RADIANStoDEGREES);

            // Calculate the geographic Y coordinate (latitude)
            result.Y = (float)(projectedCoordinate.Y * ONEOVERWGS84SEMIMAJOR * RADIANStoDEGREES);

            return result;
        }

        public PointD Project(PointD geographicCoordinate)
        {

          PointD result = new PointD();

            // Calculate the projected X coordinate
            result.X = (float)(geographicCoordinate.X * DEGREEStoRADIANS * System.Math.Cos(0) * WGS84SEMIMAJOR);

            // Calculate the projected Y coordinate
            result.Y = (float)(geographicCoordinate.Y * DEGREEStoRADIANS * WGS84SEMIMAJOR);

            // Return the result
            return result;       

        }

        public PointD Project(Position position)
        {
           PointD td = new PointD();
            td.X = ((position.Latitude.DecimalDegrees * DEGREEStoRADIANS) * System.Math.Cos(0.0)) * WGS84SEMIMAJOR;
            td.Y = (position.Longitude.DecimalDegrees * DEGREEStoRADIANS) * WGS84SEMIMAJOR;
            return td;
        }

        public PointD Project(Latitude latitude, Longitude longitude)
        {
            PointD td = new RTGeoFramework.Math.PointD();
            td.X = ((latitude.DecimalDegrees * DEGREEStoRADIANS) * System.Math.Cos(0.0)) * WGS84SEMIMAJOR;
            td.Y = (longitude.DecimalDegrees * DEGREEStoRADIANS) * WGS84SEMIMAJOR;
            return td;
        }

    }
于 2012-08-09T19:53:08.710 回答
0

我通过使用 GeoFramework 解决了这个问题,它是用于处理位置服务的开源代码。GeoFramework 的网站在这里: http ://geoframework.codeplex.com/正如它在其网站上提到的那样,GeoFramework 现在是 DotSpatial 开源项目的一部分,可以在这里找到:http://dotspatial.codeplex。 com/

我发现 GeoFramework 的一个优势是它可以在 Windows 和 Windows Mobile 上运行,这让我更进一步实现了让应用程序同时在 Windows 和 Windows Mobile 平台上运行但只有一个代码库的目标。

正如我在评论中提到的,我的客户端使用的导航软件和我的应用程序都试图打开相同的 com 端口,这导致这些应用程序之一无法建立与 com 的连接。港口。我通过使用 com 端口拆分器解决了这个问题,它将一个物理 com 端口变成了两个虚拟 com 端口。这样,我的应用程序和导航软件都能够同时读取位置数据。

于 2011-08-13T20:09:56.527 回答