private async Task AccessGeolocation() { try { var request = new GeolocationRequest(GeolocationAccuracy.Best); var location = await Geolocation.GetLocationAsync(request); Stopwatchy.Stop(); if (location != null) { TestResults.Add(new TestResult(Stopwatchy.Elapsed.TotalMilliseconds * 1000000, $"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}")); if (--NumberOfIterationsLeft > 0) { Test(); } else { var durationSum = 0.0; foreach (var testResult in TestResults) { durationSum += testResult.Duration; } var durationAvg = durationSum / TestResults.Count; TestResults.Add(new TestResult(durationAvg, "(AVERAGE) ALL TESTS FINISHED")); } } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to get location } }
private void AccelerometerChanged(object sender, AccelerometerChangedEventArgs e) { Accelerometer.ReadingChanged -= AccelerometerChanged; Stopwatchy.Stop(); var data = e.Reading; TestResults.Add(new TestResult(Stopwatchy.Elapsed.TotalMilliseconds * 1000000, "Test finished successfully (X:" + data.Acceleration.X + ", Y: " + data.Acceleration.Y + ", Z: " + data.Acceleration.Z)); if (--NumberOfIterationsLeft > 0) { Test(); } else { var durationSum = 0.0; foreach (var testResult in TestResults) { durationSum += testResult.Duration; } var durationAvg = durationSum / TestResults.Count; TestResults.Add(new TestResult(durationAvg, "(AVERAGE) ALL TESTS FINISHED")); } }