public async Task <GeolocationDto> Get2() { var start = DateTime.UtcNow; var result = new GeolocationDto(); try { var location = await Geolocation.GetLastKnownLocationAsync(); if (location == null) { // Since there is not cached location, just get one. var request = new GeolocationRequest(GeolocationAccuracy.Best) { Timeout = TimeSpan.FromSeconds(360) }; location = await Geolocation.GetLocationAsync(request); } Map(location, result); } catch (Exception ex) { /* * NOTE: ID_CAP_LOCATION access denied, if location is disabled on tthe device. */ // Logger.Error(ex, nameof(GetLocationMethodAsync)); // TODO: result.Error = ex.Message; } result.AcquireDuration = (DateTime.UtcNow - start).ToString(); return(result); }
private void Map(Location location, GeolocationDto dto) { dto.Latitude = location.Latitude; dto.Longitude = location.Longitude; dto.Altitude = location.Altitude; dto.Accuracy = location.Accuracy; dto.VerticalAccuracy = location.VerticalAccuracy; dto.Speed = location.Speed; dto.Course = location.Course; dto.Timestamp = location.Timestamp; //https://stackoverflow.com/questions/42569245/detect-or-prevent-if-user-uses-fake-location dto.IsMock = location.IsFromMockProvider; if (dto.Course == null && _compassData.HeadingMagneticNorth > 0) { dto.Course = _compassData.HeadingMagneticNorth; } }