/// <summary> /// Update the displayed route. Route calculation is done in the background thread. /// </summary> private void UpdateRoute() { var id = osmMap.DetailsRoute.Id; ThreadPool.QueueUserWorkItem(state => { var geoPoints = new List <CLLocationCoordinate2D> (); if (osmMap.GpsLocation != null) { geoPoints.Add(new CLLocationCoordinate2D(osmMap.GpsLocation.Latitude, osmMap.GpsLocation.Longitude)); } Action action; try { var locations = routeCalculator.CreateOrderedRoute(id, osmMap.GpsLocation); /*foreach (var w in locations) * { * var point = new CLLocationCoordinate2D(w.Latitude, w.Longitude); * geoPoints.Add(point); * }*/ action = () => DrawRoute(locations, osmMap.GpsLocation != null); } catch (Exception) { action = () => { }; } Device.BeginInvokeOnMainThread(() => { action.Invoke(); }); }); }
/// <summary> /// Calculates the navigation route in a seperate thread /// and throws error message if no route was found /// </summary> /// <param name="userPosition">position of the user</param> private void CalculateRoute(GeoLocation?userPosition) { var id = osmMap.DetailsRoute.Id; ThreadPool.QueueUserWorkItem(state => { Action action; try { var locations = routeCalculator.CreateOrderedRoute(id, userPosition); /*foreach (var w in locations) * { * var point = new GeoPoint (w.Latitude, w.Longitude); * geoPoints.Add (point); * }*/ action = () => DrawRoute(locations, userPosition != null); } catch (Exception) { action = () => { }; } activity.RunOnUiThread(() => { var handler = new Handler(); handler.PostDelayed(action, 0); }); }); }