Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gpsManager"></param>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="cancelToken"></param>
        /// <returns>Returns null if current position could not be determined - else returns true if in region, false otherwise</returns>
        public static async Task <bool?> IsInsideRegion(this IGpsManager gpsManager, Position center, Distance radius, CancellationToken cancelToken = default)
        {
            var result = await gpsManager.GetCurrentPosition().ToTask(cancelToken);

            var inside = result.Position.GetDistanceTo(center) < radius;

            return(inside);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the last reading (can be filtered out by maxAgeOfLastReading) otherwise request the current reading
        /// </summary>
        /// <param name="gpsManager"></param>
        /// <param name="maxAgeOfLastReading"></param>
        /// <returns></returns>
        public static IObservable <IGpsReading> GetLastReadingOrCurrentPosition(this IGpsManager gpsManager, DateTime?maxAgeOfLastReading = null) => Observable.FromAsync <IGpsReading>(async ct =>
        {
            var reading = await gpsManager.GetLastReading().ToTask(ct);
            if (reading == null || (maxAgeOfLastReading != null && reading.Timestamp < maxAgeOfLastReading.Value))
            {
                reading = await gpsManager.GetCurrentPosition().ToTask(ct);
            }

            return(reading);
        });