public async void AddFavorite(Favorite favorite) { await _favoritesService.AddFavoriteAsync(favorite); }
public void GetRoute(Geopoint point, Favorite favorit = null) { HideSearch(); if (SearchRouteCancellationToken != null) SearchRouteCancellationToken.Cancel(); SearchRouteCancellationToken = new CancellationTokenSource(); GetRouteWithToken(point, SearchRouteCancellationToken.Token, favorit); }
public async void GetRouteWithToken(Geopoint endPoint, CancellationToken token, Favorite favorite = null, int retry = 0) { if (favorite != null) { ShowSearchLocationPoint(endPoint, favorite.Name); if (userLastLocation == null) { //var dialog = new MessageDialog( // "To get there, the phone must find your location first. Please wait a bit an try again."); //await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => //{ // await dialog.ShowAsync(); //}); await MapCtrl.TrySetViewAsync(endPoint, 15, 0, null); } else { // Fit the MapControl to the route. await MapCtrl.TrySetViewBoundsAsync(MapExtensions.GetAreaFromLocations(new List<Geopoint>() { userLastLocation, endPoint }), new Thickness(40, 40, 40, 40), MapAnimationKind.None); } return; } if (userLastLocation == null) return; if (previousRouteEndingPoint == endPoint && userLastLocation == previousRouteStartingPoint) { Debug.WriteLine("Skip route finder : same location provided."); return; } previousRouteStartingPoint = userLastLocation; previousRouteEndingPoint = endPoint; var task = FindRoute(userLastLocation, endPoint); if (task != await Task.WhenAny(task, Task.Delay(2000, token))) { MapCtrl.Routes.Clear(); // timout case Debug.WriteLine("get route TIMEOUT or CANCELED !"); // BUG : apparently MapRouteFinder.GetWalkingRouteAsync is on UI thread. don't recall it again // if (!token.IsCancellationRequested && retry < 5) // GetRouteWithToken(endPoint, token, null, ++retry); return; } var routeResult = task.Result; //var routeResult = task.Result; Debug.WriteLine("get route ended with result : " + routeResult.Status); if (routeResult.Status == MapRouteFinderStatus.Success) { // Use the route to initialize a MapRouteView. MapRouteView viewOfRoute = new MapRouteView(routeResult.Route); viewOfRoute.RouteColor = new SolidColorBrush((Application.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color).Color; viewOfRoute.OutlineColor = Colors.Black; if (previousMapRoute == null || previousMapRoute.LengthInMeters != routeResult.Route.LengthInMeters) { MapCtrl.Routes.Clear(); Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { // Add the new MapRouteView to the Routes collection // of the MapControl. MapCtrl.Routes.Add(viewOfRoute); ShowUserLocation(); }); } previousMapRoute = routeResult.Route; } else { MapCtrl.Routes.Clear(); } }
public void GoToFavorite(Favorite favorite) { FireGoToFavorite?.Invoke(favorite, EventArgs.Empty); }
public async Task RemoveFavoriteAsync(Favorite favorite) { await _storageService.RemoveAsync(favorite.ToString()).ConfigureAwait(false); }
public async Task AddFavoriteAsync(Favorite favorite) { await _storageService.StoreAsync(favorite.ToString(), favorite).ConfigureAwait(false); }