コード例 #1
0
        private void Finish(Location location)
        {
            var p = new Position();

            if (location.HasAccuracy)
            {
                p.Accuracy = location.Accuracy;
            }
            if (location.HasAltitude)
            {
                p.Altitude = location.Altitude;
            }
            if (location.HasBearing)
            {
                p.Heading = location.Bearing;
            }
            if (location.HasSpeed)
            {
                p.Speed = location.Speed;
            }

            p.Longitude = location.Longitude;
            p.Latitude  = location.Latitude;
            p.Timestamp = GeolocatorImplementation.GetTimestamp(location);

            if (this.finishedCallback != null)
            {
                this.finishedCallback();
            }

            this.completionSource.TrySetResult(p);
        }
コード例 #2
0
        public void OnLocationChanged(Location location)
        {
            if (location.Provider != this.activeProvider)
            {
                if (this.activeProvider != null && this.manager.IsProviderEnabled(this.activeProvider))
                {
                    LocationProvider pr     = this.manager.GetProvider(location.Provider);
                    TimeSpan         lapsed = GetTimeSpan(location.Time) - GetTimeSpan(this.lastLocation.Time);

                    if (pr.Accuracy > this.manager.GetProvider(this.activeProvider).Accuracy &&
                        lapsed < timePeriod.Add(timePeriod))
                    {
                        location.Dispose();
                        return;
                    }
                }

                this.activeProvider = location.Provider;
            }

            var previous = Interlocked.Exchange(ref this.lastLocation, location);

            if (previous != null)
            {
                previous.Dispose();
            }

            var p = new Position();

            if (location.HasAccuracy)
            {
                p.Accuracy = location.Accuracy;
            }
            if (location.HasAltitude)
            {
                p.Altitude = location.Altitude;
            }
            if (location.HasBearing)
            {
                p.Heading = location.Bearing;
            }
            if (location.HasSpeed)
            {
                p.Speed = location.Speed;
            }

            p.Longitude = location.Longitude;
            p.Latitude  = location.Latitude;
            p.Timestamp = GeolocatorImplementation.GetTimestamp(location);

            var changed = PositionChanged;

            if (changed != null)
            {
                changed(this, new PositionEventArgs(p));
            }
        }