public static void SaveLocation(Mlocation mlocation) { try { if (!isTableExiste()) { db.CreateTable <Mlocation>(); } if (mlocation != null) { db.Insert(mlocation); lasLocationId = mlocation._id; Messages.ToastMessage("Inserted successfully"); } else { Messages.ToastMessage($"Something hapened: {mlocation} Not successfully add"); } //var con = new SQLiteAsyncConnection("", SQLiteOpenFlags.Create); } catch (Exception ex) { Messages.DisplayAlert(message: $"isTableExiste:{ex.Message}"); } }
public static Mlocation GetLastLocation() { Mlocation lastLocation = null; try { if (TableNotEmpty()) { var query = db.Query <Mlocation>("select * from MLocations order by _id desc limit 1"); lastLocation = query[0]; } } catch (SQLiteException ex) { Messages.DisplayAlert(message: $"isTableExiste:{ex.Message}"); } return(lastLocation); }
public static void UpdateTable(string locationPersonal = "") { Mlocation lastLoc; Location currLocation; try { var time = DateTime.Now.ToLocalTime(); currLocation = XamEssentialFeatures.currentLocation; var myLoc = new Mlocation() { address = XamEssentialFeatures.address, latitude = currLocation.Latitude, longitude = currLocation.Longitude, time = time, accuracy = (double)currLocation.Accuracy, personalName = locationPersonal }; lastLoc = GetLastLocation(); if (lastLoc != null) { Location location = new Location(lastLoc.latitude, lastLoc.longitude); if (isDiff10(location, currLocation)) { SaveLocation(myLoc); } else { Messages.ToastMessage("Not added:The last location is too near the current location"); } } else { myLoc._id = 1; SaveLocation(myLoc); } } catch (Exception ex) { Messages.DisplayAlert(message: ex.Message); } }