Click here to Skip to main content
15,893,564 members
Articles / Mobile Apps / Windows Mobile

My Experience with the Windows Marketplace for Mobile and Windows Mobile 6

Rate me:
Please Sign up or sign in to vote.
4.89/5 (12 votes)
22 Mar 2010CPOL27 min read 27.8K   193   14  
My experience with the Windows Marketplace for Mobile for 6.x devices and the certification process.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using SpeedTracker.Common;
using SpeedTracker.Converters;
using SpeedTracker.Gps;



namespace SpeedTracker
{
    class GpsLocationProvider : ILocationProvider
    {
        private const string ProviderName = "GPSID Provider";
        private GpsId _gpsId;

        private bool _hasFix = false;
        private bool _isActive = false;
        private int _fixQuality = 0;
        private IValueConverter _speedConverter=null;

        private Location _lastLocation = new Location();
        public object SyncRoot = new object();
        public GpsLocationProvider()
        {
            _speedConverter = SpeedTracker.Converters.ConverterCatalog.GetConverter(new ConversionUnitNames("nautical mile", "kilometer"));
        }

        #region ILocationProvider Members

        public string Name
        {
            get { return ProviderName; }
        }

        public event EventHandler<LocationUpdatedEventArgs> LocationUpdated;

        protected void OnLocationUpdated(Location newLocation)
        {
            if (LocationUpdated != null)
            lock (SyncRoot)
            {
                if (LocationUpdated != null)
                {
                    LocationUpdated(this, new LocationUpdatedEventArgs() {NewLocation = newLocation});
                }
            }
        }

        public bool IsActive
        {
            get { return _isActive; }
        }

        public bool HasFix
        {
            get { return _hasFix; }
        }

        public Location LastLocation
        {
            get { return _lastLocation; }
        }

        public void Start()
        {
            if(_gpsId==null)
            {
                _gpsId = new GpsId();
                _gpsId.LocationChanged += new LocationChangedEventHandler(gpsId_LocationChanged);
                _gpsId.DeviceStateChanged += new DeviceStateChangedEventHandler(_gpsId_DeviceStateChanged);
            }
            if(_gpsId!=null)
            {
                _gpsId.Open();
                _isActive = true;
            }
        }

        void _gpsId_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
        {
            
        }


        void gpsId_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            if(!_isActive)
                return;
            Location newLoc = new Location() {TimeStamp = DateTime.MinValue};
            newLoc.IsLocationValid  = _hasFix = (args.Position != null) && (args.Position.LongitudeValid && args.Position.LongitudeValid);
            if (_hasFix)
            {
                newLoc.Latitude = args.Position.Latitude;
                newLoc.Longitude = args.Position.Longitude;
                newLoc.Speed =
                    (float) (double) _speedConverter.Convert((double)args.Position.Speed, typeof (double), null, null);
                newLoc.Heading = args.Position.Heading;
                newLoc.TimeStamp = args.Position.Time;
            }
            this._lastLocation = newLoc;

            OnLocationUpdated(newLoc);

        }

        public void Stop()
        {
            if (_gpsId != null)
            {
                _gpsId.Close();
                _gpsId.LocationChanged -= (gpsId_LocationChanged);
                _gpsId.DeviceStateChanged -= (_gpsId_DeviceStateChanged);
            }
            _isActive = false;
            _hasFix = false;
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {

        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet


Comments and Discussions