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

posted @ 2010-11-08 19:26  HOH  阅读(700)  评论(0编辑  收藏  举报