public void AddLocation(LocationsBackGround_Model data) { if (_connection != null) { _connection.Insert(data); } }
public async Task GetLocationAsync() { try { Position position = null; List <double> coords = new List <double>(); string LogguedIn = null; if (CrossSecureStorage.Current.HasKey("LogguedIn")) { LogguedIn = CrossSecureStorage.Current.GetValue("LogguedIn"); } if (LogguedIn == "True") { try { if (await PermissionsRequest.Check_permissions("Location") == Xamarin.Essentials.PermissionStatus.Granted) { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 100; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { position = null; position = await locator.GetPositionAsync(TimeSpan.FromSeconds(9), null, true); if (position != null) { if (coords.Count > 0) { coords.RemoveAt(0); coords.RemoveAt(1); } coords.Insert(0, position.Latitude); coords.Insert(1, position.Longitude); var location = new LocationsBackGround_Model { Coords = coords, Date = DateTime.Now, }; DataStore.AddLocation(location); } } else { Device.BeginInvokeOnMainThread(() => { DependencyService.Get <ISettingService>().OpenSettings(); }); } } } catch (Exception ex) { } } } catch (Exception ex) { } }