Example #1
0
        private async Task PublishLastKnownLocationAsync(IObserver <IGpsLocation> observer)
        {
            try
            {
                var lastKnownLocation = await _proxy.GetLastKnownLocationAsync();

                if (lastKnownLocation == null)
                {
                    _analyticsService.Trace(this, "Last known location is null");
                }
                else
                {
                    var lastLocation = GpsLocation.Create(lastKnownLocation.Latitude, lastKnownLocation.Longitude);
                    if (lastLocation.IsFailure)
                    {
                        _analyticsService.TraceError(this, lastLocation.Error, lastKnownLocation.ToObjectDictionary());
                        observer.OnError(new ErrorException(lastLocation.Error));
                    }
                    else
                    {
                        _analyticsService.Trace(this, "Last known location published");
                        observer.OnNext(lastLocation.Value);
                    }
                }
            }
            catch (Exception e)
            {
                _analyticsService.LogException(this, e);
                observer.OnError(new ErrorException(GeolocationErrors.Unexpected, e));
            }
        }
Example #2
0
        private async Task PublishCurrentLocationAsync(GeolocationRequest geolocationRequest, IObserver <IGpsLocation> observer, string description)
        {
            try
            {
                var currentLocation = await _proxy.GetCurrentLocationAsync(geolocationRequest);

                if (currentLocation == null)
                {
                    _analyticsService.TraceWarning(this, $"{description} location is null");
                }
                else
                {
                    var currentGpsLocation = GpsLocation.Create(currentLocation.Latitude, currentLocation.Longitude);
                    if (currentGpsLocation.IsFailure)
                    {
                        _analyticsService.TraceError(this, currentGpsLocation.Error, currentLocation.ToObjectDictionary());
                        observer.OnError(new ErrorException(currentGpsLocation.Error));
                    }
                    else
                    {
                        _analyticsService.Debug($"{description} location published");
                        observer.OnNext(currentGpsLocation.Value);
                    }
                }
            }
            catch (Exception e)
            {
                _analyticsService.LogException(this, e);
                observer.OnError(new ErrorException(GeolocationErrors.Unexpected, e));
            }
        }