【问题标题】:What is the equivalent of GPS Intermediate Driver for the Windows platform?Windows 平台的 GPS 中间驱动程序相当于什么?
【发布时间】:2011-08-01 13:49:43
【问题描述】:

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

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

【问题讨论】:

  • 我想你回到了 COM 端口。
  • 这就是我害怕的! ;) 感谢您的回复,亨克。这是否意味着如果我通过 COM 端口建立与接收器的连接,该端口将被其他试图使用同一接收器的导航软件阻止?
  • 以前是这样...我过去使用过拆分器(XP),但结果好坏参半。
  • 你能告诉我你用的是哪个分离器吗?谢谢。
  • 嗯,我认为它被称为 Com-foolery。但是四处寻找,还有其他人。

标签: c# .net windows gps.net


【解决方案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;
        }

    }

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-12
      • 2010-12-13
      • 2011-10-29
      • 2012-02-01
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      • 2012-12-05
      相关资源
      最近更新 更多