public async Task TimerCheck(CustomMap map) { Device.StartTimer(TimeSpan.FromSeconds(DESIRED_SECONDS), () => { try { OnLocationCheck(map); lc.AddToPositionsHistory(new Plugin.Geolocator.Abstractions.Position(currLat, currLong)); if (DistanceBetween(currLat, currLong, p.x, p.y) > DESIRED_DISTANCE) { DisplayAlert(AppResources.not_arrived, DistanceBetween(currLat, currLong, p.x, p.y).ToString() + "curr lat: " + currLat.ToString() + "curr long: " + currLong.ToString() + "x: " + p.x + "y: " + p.y + " point info: " + nextAttraction.name, AppResources.close); return(true); } else { gc.EditScore(ScoreRule.Kinds.Attraction_Arrive); DisplayAlert(AppResources.arrived, AppResources.arrived + "! " + DistanceBetween(currLat, currLong, p.x, p.y).ToString(), AppResources.close); Application.Current.MainPage = new AttractionPage(); return(false); } // True = Repeat again, False = Stop the timer } catch (Exception e) { return(false); } }); }
public void TimerCheck() { Timer arrivedTimer = new Timer(); arrivedTimer.Interval = DESIRED_SECONDS * 1000; arrivedTimer.Elapsed += (o, e) => { /* * Device.BeginInvokeOnMainThread(() => { * DisplayAlert("Must come closer", lc.DistanceBetween(currLoc.x, currLoc.y, attractionLoc.x, attractionLoc.y).ToString() + "\ncurr lat: " + currLoc.x + "\ncurr long: " + currLoc.y + "\nattractionLoc x: " + attractionLoc.x + "\nattractionLoc y: " + attractionLoc.y + "\npoint info: " + nextAttraction.name, "close"); * }); */ if (done) { arrivedTimer.Stop(); } currLoc = gc.GetUserLocation(); if (firstTimeLocationUpdate) { firstTimeLocationUpdate = false; startDistanceToDestination = lc.DistanceBetween(currLoc.x, currLoc.y, attractionLoc.x, attractionLoc.y); } lc.AddToPositionsHistory(new Plugin.Geolocator.Abstractions.Position(currLoc.x, currLoc.y)); //myMap.AddCurrlocationToMap(currLoc); myMap.OnTimerCheck(new Plugin.Geolocator.Abstractions.Position(currLoc.x, currLoc.y)); //myMap.AddPointToMap(currLoc); //myMap.DrawPastPath(); double currentDistanceToDestination = lc.DistanceBetween(currLoc.x, currLoc.y, attractionLoc.x, attractionLoc.y); if (currentDistanceToDestination > DESIRED_DISTANCE) { //if (ServerConection.DEBUG == 1) // Device.BeginInvokeOnMainThread (() => { // DisplayAlert("Must come closer", lc.DistanceBetween(currLoc.x, currLoc.y, attractionLoc.x, attractionLoc.y).ToString() + "\ncurr lat: " + currLoc.x + "\ncurr long: " + currLoc.y + "\nattractionLoc x: " + attractionLoc.x + "\nattractionLoc y: " + attractionLoc.y + "\npoint info: " + nextAttraction.name, "close"); // }); double percentApproachingTarget = Math.Max(0, Math.Min(1, (1 - (currentDistanceToDestination / startDistanceToDestination)))); odometer.Value = percentApproachingTarget; if (percentApproachingTarget < 0.3) { odometer.MinimumTrackColor = Color.FromHex("#0066ff"); odometer.MaximumTrackColor = Color.FromHex("#0066ff"); } else { if (percentApproachingTarget < 0.7) { odometer.MinimumTrackColor = Color.FromHex("#b21f4c"); odometer.MaximumTrackColor = Color.FromHex("#b21f4c"); } else { odometer.MinimumTrackColor = Color.FromHex("#ff0000"); odometer.MaximumTrackColor = Color.FromHex("#ff0000"); } } } else { Device.BeginInvokeOnMainThread(() => Arrived()); } }; arrivedTimer.Start(); }