Пример #1
0
        public static bool TryParse(string s, out GpsLocation result)
        {
            result = new GpsLocation();

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            int pos = 0;

            double latitude  = double.NaN;
            double longitude = double.NaN;

            if (!TryParseGpsFragment(s, ref pos, ref latitude, ref longitude))
            {
                return(false);
            }
            if (!TryParseGpsFragment(s, ref pos, ref latitude, ref longitude))
            {
                return(false);
            }
            if (!IsValidLatitude(latitude) || !IsValidLongitude(longitude))
            {
                return(false);
            }

            result.Latitude  = latitude;
            result.Longitude = longitude;
            return(true);
        }
Пример #2
0
        protected void processGpsMessage(string gpsMessage)
        {
            short status = nmeaParser.Parse(gpsMessage);

            switch (status)
            {
            case NmeaParser.LOCATION:
                if (locationChanged != null)
                {
                    GpsLocation gpsLoc = this.nmeaParser.getLocationData();
                    if (gpsLoc != null)
                    {
                        locationChanged(gpsLoc);
                    }
                }
                break;

            case NmeaParser.SATELLITE:
                if (satellitesChanged != null)
                {
                    //satellitesChanged(gpsSatelites);
                }
                break;

            case NmeaParser.UNRECOGNIZED:
                break;

            case NmeaParser.CHECKSUM_INVALID:
                break;
            }
        }
Пример #3
0
        public override bool Equals(object obj)
        {
            if (!(obj is GpsLocation))
            {
                return(false);
            }

            GpsLocation other = (GpsLocation)obj;

            return(this.Latitude == other.Latitude && this.Longitude == other.Longitude);
        }
Пример #4
0
        // images - hashtable (Point => Bitmap)
        public MapView(GpsLocation gpsLocation, Point centerImgPosition, Hashtable viewParts, Point[] orderingPoints)
        {
            // check if view parts contains center image
            if (viewParts[new Point(1, 1)] == null)
                throw new Exception("Can't instantiate map view without center image!");
            this.gpsLocation = gpsLocation;
            this.viewParts = viewParts;

            this.centerImgPosition = centerImgPosition;

            this.orderingPoints = orderingPoints;
        }
Пример #5
0
        public GpsLocation getLocationData()
        {
            GpsLocation gpsLoc = new GpsLocation(
                RecivedData.SatelliteTime,
                RecivedData.LatitudeString,
                RecivedData.LongitudeString,
                RecivedData.Speed,
                RecivedData.Course
                );

            return(gpsLoc);
        }
Пример #6
0
 public bool isLocationSignificant(GpsLocation newLocation)
 {
     if (gpsLocationsCache.Count == 0)
     {
         // when there is no cache location new location must be significant
         return true;
     }
     double deltaLocation = getLocationsDistance(gpsLocationsCache[0], newLocation);
     // if distance is to small skip processing
     if (deltaLocation < MIN_DELTA_LOCATION)
     {
         Debug.WriteLine("delta location to small.", this.ToString());
         return false;
     }
     return true;
 }
Пример #7
0
 public void update(GpsLocation currentGpsLocation, MapPackage currentMapPkg, int currentZoom)
 {
     this.currentGpsLocation = currentGpsLocation;
     this.currentMapPkg = currentMapPkg;
     this.currentZoom = currentZoom;
 }
Пример #8
0
 public void setGpsLocation(GpsLocation gpsLocation)
 {
     this.gpsLocation = gpsLocation;
 }
Пример #9
0
 public bool isValidForGpsLocation(GpsLocation gpsLoc)
 {
     return this.centerImgArea.contains(gpsLoc.getLatitude(), gpsLoc.getLongitude());
 }
Пример #10
0
        public void newPosition(GpsLocation gpsLocation)
        {
            // when gps location isn't known (invalid) skip processing
            if (!gpsLocation.isValid())
                return;
            // when delta location is to small skip processing
            if (!this.gpsDataAnalyzer.isLocationSignificant(gpsLocation))
                return;
            // add location to gps data analyzer
            this.gpsDataAnalyzer.addGpsLocation(gpsLocation);
            // set current gps location
            this.currentGpsLocation = gpsLocation;
            // update current map package
            retrieveCurrentMapPkg();
            // when there is no map for location stop processing
            if (this.currentMapPkg == null)
                return;
            // update map view builder
            this.mapViewBuilder.update(currentGpsLocation, currentMapPkg, currentZoom);
            // update current map view or create new one if current doesn't match gps location
            if (mapViewBuilder.getResult() != null
                && mapViewBuilder.getResult().isValidForGpsLocation(this.currentGpsLocation))
            {
                // when current map view match gps location update it
                mapViewBuilder.adjustCurrent();
            }
            else
            {
                // create new map view when current doesn't match gps location
                mapViewBuilder.createNew();
                if (this.loadingEventMsg != "")
                    mapLoaded();
                // find current named area for pois by current gps location
                findCurrentArea();
                // find and set pois on newly created map view
                mapViewBuilder.loadPois();
            }
            // update current map view estimated course
            mapViewBuilder.loadCourse();
            // update current map view target
            mapViewBuilder.loadTarget();

            if (mapViewBuilder.getResult() != null)
            {
                // display map view
                this.mapDisplayer.displayView(mapViewBuilder.getResult());
            }
        }
Пример #11
0
 private double getLocationsDistance(GpsLocation gl1, GpsLocation gl2)
 {
     // distance between two points
     return Math.Sqrt(Math.Pow(gl2.getLatitude() - gl1.getLatitude(), 2) +
                         Math.Pow(gl2.getLongitude() - gl1.getLongitude(), 2));
 }
Пример #12
0
 public void addGpsLocation(GpsLocation gpsLoc)
 {
     gpsLocationsCache.Insert(0, gpsLoc);
     removeExcess();
 }
Пример #13
0
        public static bool TryParse(string s, out GpsLocation result)
        {
            result = new GpsLocation();

            if (string.IsNullOrEmpty(s)) return false;

            int pos = 0;

            double latitude = double.NaN;
            double longitude = double.NaN;

            if (!TryParseGpsFragment(s, ref pos, ref latitude, ref longitude)) return false;
            if (!TryParseGpsFragment(s, ref pos, ref latitude, ref longitude)) return false;
            if (!IsValidLatitude(latitude) || !IsValidLongitude(longitude)) return false;

            result.Latitude = latitude;
            result.Longitude = longitude;
            return true;
        }
Пример #14
0
 public void locationChanged(GpsLocation gpsLoc)
 {
     this.currentGpsLocation = gpsLoc;
     Invoke(this.updatePosHandler);
 }
Пример #15
0
 public GpsLocation getLocationData()
 {
     GpsLocation gpsLoc = new GpsLocation(
         RecivedData.SatelliteTime,
         RecivedData.LatitudeString,
         RecivedData.LongitudeString,
         RecivedData.Speed,
         RecivedData.Course
     );
     return gpsLoc;
 }