PDA开发系列:GPS模块的调用

     在wince6.0中,要调用GPS模块,其实是一件很容易的事情。

    在wince6.0中,如果要调用GPS模块,其实很简单,微软已经为我们做好了这一切,我们只需要在自己的解决方案中,添加对Microsoft.WindowsMobile.Samples.Location.dll的引用就可以了,然后获取一个GPS的实例,如下:

        static Gps _Gps = null;
        /// <summary>
        /// 获取GPS设备
        /// </summary>
        public Gps GpsDevice
        {
            get
            {
                if (_Gps == null)
                {
                    lock (typeof(Gps))
                    {
                        if (_Gps == null)
                        {
                            _Gps = new Gps();
                        }
                    }
                }
                return _Gps;
            }
        }
然后注册LocationChanged的事件,打开GPS设备就可以了,如下:
GpsDevice.LocationChanged += new LocationChangedEventHandler(GpsDevice_LocationChanged);

        void GpsDevice_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            try
            {
                if (PdaServer.PDAServer.IsRun && PdaServer.PDAServer.GpsDevice.Opened)
                {
                    //经度
                    double Longitude = args.Position.Longitude;
                    //纬度
                    double Latitude = args.Position.Latitude;
                    if (Longitude > 0 && Latitude > 0)
                    {
                        //上传GPS
                    }
                }
            }
            catch { }
        }

其他相关的属性和方法见该dll。

相关下载:Microsoft.WindowsMobile.Samples.Location.rar

作者:HOH
出处:http://hoh.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/HOH/p/1872033.html