Esempio n. 1
0
        private async void SolveRouteClick(object sender, EventArgs e)
        {
            // Create a new route task using the San Diego route service URI
            RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

            // Get the default parameters from the route task (defined with the service)
            RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

            // Make some changes to the default parameters
            routeParams.ReturnStops      = true;
            routeParams.ReturnDirections = true;

            // Set the list of route stops that were defined at startup
            routeParams.SetStops(_routeStops);

            // Solve for the best route between the stops and store the result
            RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

            // Get the first (should be only) route from the result
            Route firstRoute = solveRouteResult.Routes.First();

            // Get the route geometry (polyline)
            Polyline routePolyline = firstRoute.RouteGeometry;

            // Create a thick purple line symbol for the route
            SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Purple, 8.0);

            // Create a new graphic for the route geometry and add it to the graphics overlay
            Graphic routeGraphic = new Graphic(routePolyline, routeSymbol);

            _routeGraphicsOverlay.Graphics.Add(routeGraphic);

            // Get a list of directions for the route and display it in the list box
            DirectionsListBox.ItemsSource = firstRoute.DirectionManeuvers.Select(direction => direction.DirectionText);
        }
Esempio n. 2
0
        private async Task CreateRouteTask()
        {
            try
            {
                Router = await RouteTask.CreateAsync(new Uri(Configuration.RouteUrl));
            }
            catch (Exception ex)
            {
                //TODO: Remove workaround when iOS bug is fixed
#if __IOS__
                exceptionCounter++;
                if (ex.Message == "403 (Forbidden)" && exceptionCounter <= 3)
                {
                    var credential = AuthenticationManager.Current.FindCredential(new Uri(Configuration.RouteUrl));
                    await CreateRouteTask();

                    return;
                }
#endif
                // This is returned when user hits the Cancel button in iOS or the back arrow in Android
                // It does not get caught in the SignInRenderer and needs to be handled here
                if (ex.Message.Contains("Token Required"))
                {
                    FromPlace = null;
                    ToPlace   = null;
                    IsBusy    = false;
                    return;
                }

                exceptionCounter = 0;
                throw ex;
            }
        }
        private async Task CreateRouteTask()
        {
            try
            {
                Router = await RouteTask.CreateAsync(new Uri(Configuration.RouteUrl));
            }
            catch (Exception)
            {
                // Try one more time, to work around a bug. dotnet-api/6024
                try
                {
                    var credential = await AuthenticationManager.Current.GenerateCredentialAsync(new Uri(Configuration.RouteUrl));

                    AuthenticationManager.Current.AddCredential(credential);
                    Router = await RouteTask.CreateAsync(new Uri(Configuration.RouteUrl));
                }
                catch (Exception exx)
                {
                    // This is returned when user hits the Cancel button in iOS or the back arrow in Android
                    // It does not get caught in the SignInRenderer and needs to be handled here
                    if (exx.Message.Contains("Token Required"))
                    {
                        FromPlace = null;
                        ToPlace   = null;
                        IsBusy    = false;
                        return;
                    }

                    throw;
                }
            }
        }
Esempio n. 4
0
 //Thread safe initialization of the route task
 private static Task <RouteTask> InitRouterAsync()
 {
     if (initializeTask == null)
     {
         string path = System.IO.Path.Combine(MapViewModel.GetDataFolder(), "Network/IndoorNavigation.geodatabase");
         initializeTask = RouteTask.CreateAsync(path, "Transportation_ND");
     }
     return(initializeTask);
 }
        private async void Initialize()
        {
            try
            {
                // Update interface state.
                UpdateInterfaceState(SampleState.NotReady);

                // Create the map with a basemap.
                Map sampleMap = new Map(Basemap.CreateTopographicVector());
                sampleMap.InitialViewpoint = new Viewpoint(32.7157, -117.1611, 1e5);
                _myMapView.Map             = sampleMap;

                // Create the graphics overlays. These will manage rendering of route, direction, stop, and barrier graphics.
                _routeOverlay    = new GraphicsOverlay();
                _stopsOverlay    = new GraphicsOverlay();
                _barriersOverlay = new GraphicsOverlay();

                // Add graphics overlays to the map view.
                _myMapView.GraphicsOverlays.Add(_routeOverlay);
                _myMapView.GraphicsOverlays.Add(_stopsOverlay);
                _myMapView.GraphicsOverlays.Add(_barriersOverlay);

                // Create and initialize the route task.
                _routeTask = await RouteTask.CreateAsync(new Uri(RouteServiceUrl));

                // Get the route parameters from the route task.
                _routeParameters = await _routeTask.CreateDefaultParametersAsync();

                // Prepare symbols.
                _routeSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _barrierSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Red, null);

                // Configure directions display.
                _directionsViewModel = new DirectionsViewModel(_directions);

                // Create the table view controller for displaying directions.
                _directionsController = new UITableViewController(UITableViewStyle.Plain);

                // The table view content is managed by the view model.
                _directionsController.TableView.Source = _directionsViewModel;

                // Create the view controller for configuring the route.
                _routeSettingsController = new RouteSettingsViewController();

                // Enable the UI.
                UpdateInterfaceState(SampleState.Ready);
            }
            catch (Exception e)
            {
                UpdateInterfaceState(SampleState.NotReady);
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't load sample", "Couldn't start the sample. See the debug output for detail.");
            }
        }
        private async Task FindRoute()
        {
            // Manage Buttons
            AcceptNavigation.Visibility = Visibility.Visible;
            AcceptNavigation.IsEnabled  = true;
            RefuseNavigation.Visibility = Visibility.Visible;
            RefuseNavigation.IsEnabled  = true;
            CancelNavigation.Visibility = Visibility.Hidden;
            CancelNavigation.IsEnabled  = false;
            TripRequestTB.Visibility    = Visibility.Visible;

            try
            {
                _solveRouteTask = await RouteTask.CreateAsync(_transportationNetwork);

                _routeParameters = await _solveRouteTask.CreateDefaultParametersAsync();

                var truckMode = from travelmode in _solveRouteTask.RouteTaskInfo.TravelModes
                                where travelmode.Type == "TRUCK"
                                select travelmode;
                _routeParameters.TravelMode             = truckMode.Last();
                _routeParameters.ReturnDirections       = true;
                _routeParameters.ReturnStops            = true;
                _routeParameters.ReturnRoutes           = true;
                _routeParameters.OutputSpatialReference = SpatialReferences.Wgs84;

                List <Stop> stops = new List <Stop> {
                    new Stop(_mapView.LocationDisplay.MapLocation),
                    new Stop(_startPoint)
                };
                _routeParameters.SetStops(stops);

                _routeResult = await _solveRouteTask.SolveRouteAsync(_routeParameters);

                _route = _routeResult.Routes.FirstOrDefault();

                // Display UI info
                TimeTB     = _route.TotalTime.ToString(@"hh\:mm\:ss");
                DistanceTB = Math.Round(_route.TotalLength / 1000, 2).ToString();

                // Diplay the route
                Polyline         routePolyline = _route.RouteGeometry;
                SimpleLineSymbol routeSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.BlueViolet, 4.0f);
                Graphic          routeGraphic  = new Graphic(routePolyline, routeSymbol);
                _graphicsOverlay.Graphics.Add(routeGraphic);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            setExtent(_mapView.LocationDisplay.MapLocation, _startPoint);
            //StartNavigation();
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the requested route based on start and end location points.
        /// </summary>
        /// <returns>The requested route.</returns>
        /// <param name="fromLocation">From location.</param>
        /// <param name="toLocation">To location.</param>
        internal async Task <RouteResult> GetRequestedRouteAsync(MapPoint fromLocation, MapPoint toLocation)
        {
            if (this.Map.LoadStatus != Esri.ArcGISRuntime.LoadStatus.Loaded)
            {
                try
                {
                    await this.Map.LoadAsync();
                }
                catch
                {
                    return(null);
                }
            }

            try
            {
                var routeTask = await RouteTask.CreateAsync(this.Map.TransportationNetworks[0]);

                if (routeTask != null)
                {
                    // Get the default route parameters
                    var routeParams = await routeTask.CreateDefaultParametersAsync();

                    // Explicitly set values for some params
                    // Indoor networks do not support turn by turn navigation
                    routeParams.ReturnRoutes     = true;
                    routeParams.ReturnDirections = true;

                    // Create stops
                    var startPoint = new Stop(fromLocation);
                    var endPoint   = new Stop(toLocation);

                    // assign the stops to the route parameters
                    routeParams.SetStops(new List <Stop> {
                        startPoint, endPoint
                    });

                    // Execute routing
                    var routeResult = await routeTask.SolveRouteAsync(routeParams);

                    return(routeResult);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 8
0
        public async Task <RouteResult> GetRoute(IEnumerable <MapPoint> stops, CancellationToken cancellationToken)
        {
            if (stops == null)
            {
                throw new ArgumentNullException("stops");
            }

            List <Stop> stopList = new List <Stop>();

            foreach (var stop in stops)
            {
                stopList.Add(new Stop(stop));
            }
            if (stopList.Count < 2)
            {
                throw new ArgumentException("Not enough stops");
            }

            string svc = routeService;

            try
            {
                //Calculate route
                RouteTask task = await RouteTask.CreateAsync(new Uri(svc), credential).ConfigureAwait(false);

                var parameters = await task.CreateDefaultParametersAsync().ConfigureAwait(false);

                parameters.SetStops(stopList);
                parameters.ReturnStops             = true;
                parameters.ReturnDirections        = true;
                parameters.RouteShapeType          = RouteShapeType.TrueShapeWithMeasures;
                parameters.OutputSpatialReference  = SpatialReferences.Wgs84;
                parameters.DirectionsDistanceUnits = Esri.ArcGISRuntime.UnitSystem.Metric;
                parameters.StartTime = DateTime.UtcNow;
                return(await task.SolveRouteAsync(parameters));
            }
            catch (System.Exception ex)
            {
                if (ex is Esri.ArcGISRuntime.Http.ArcGISWebException)
                {
                    var webex = (Esri.ArcGISRuntime.Http.ArcGISWebException)ex;
                    if (webex.Details.FirstOrDefault()?.Contains("Unlocated") == true)
                    {
                        //This occurs if the server couldn't find a route to the location
                        return(null);
                    }
                }
                throw;
            }
        }
Esempio n. 9
0
        private async Task <RouteTask> GetRouter()
        {
            if (UseOnlineService)
            {
                return(await RouteTask.CreateAsync(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/Route")));
            }
            try
            {
                BusyMessage = "Loading network...";
#if NETFX_CORE
                string path       = "Data\\Networks";
                var    foldername = Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "\\" + path;
                var    datafolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(foldername);

                var folders = await datafolder.GetFoldersAsync();

                foreach (var folder in folders)
                {
                    var files = await folder.GetFilesAsync();

                    var file = files.Where(f => f.Name.EndsWith(".db")).FirstOrDefault();
                    if (file != null) //Locator found
                    {
                        return(await RouteTask.CreateAsync(file.Path, "Streets_ND"));
                    }
                }
#else
                string path = "..\\..\\..\\Data\\Networks";
                foreach (var folder in new System.IO.DirectoryInfo(path).GetDirectories())
                {
                    var file = folder.GetFiles("*.db").FirstOrDefault();
                    if (file != null) //Locator found
                    {
                        return(await RouteTask.CreateAsync(file.FullName, "Streets_ND"));
                    }
                }
#endif
            }
            catch
            {
                throw;
            }
            finally
            {
                BusyMessage = "";
            }
            return(null);
        }
Esempio n. 10
0
        private async void Initialize()
        {
            // Create and show a map.
            _mapView.Map = new Map(Basemap.CreateImagery());

            try
            {
                // Enable location display.
                _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter;
                await _mapView.LocationDisplay.DataSource.StartAsync();

                _mapView.LocationDisplay.IsEnabled = true;

                // Configure authentication.
                SetOAuthInfo();
                var credential = await AuthenticationManager.Current.GenerateCredentialAsync(_routingUri);

                AuthenticationManager.Current.AddCredential(credential);

                // Create the route task.
                _routeTask = await RouteTask.CreateAsync(_routingUri);

                // Create route display overlay and symbology.
                _routeOverlay = new GraphicsOverlay();
                SimpleLineSymbol routeSymbol =
                    new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Yellow, 1);
                _routeOverlay.Renderer = new SimpleRenderer(routeSymbol);

                // Create stop display overlay.
                _stopsOverlay = new GraphicsOverlay();

                // Add the overlays to the map.
                _mapView.GraphicsOverlays.Add(_routeOverlay);
                _mapView.GraphicsOverlays.Add(_stopsOverlay);

                // Enable tap-to-place stops.
                _mapView.GeoViewTapped += MapView_GeoViewTapped;

                // Update the UI.
                _helpLabel.Text = "Tap to set a start point";
            }
            catch (Exception ex)
            {
                new Android.Support.V7.App.AlertDialog.Builder(this).SetMessage("Failed to start sample")
                .SetTitle("Error").Show();
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Esempio n. 11
0
        public static async Task InitializeAsync(Portal.ArcGISPortal portal)
        {
            string?url = portal.PortalInfo.HelperServices.RouteService?.Url;

            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException("The provided portal does not have a routing service configured");
            }
            var c = portal.Credential;

            if (c == null)
            {
                throw new ArgumentException("User does not have a credential");
            }
            _routeTask = await RouteTask.CreateAsync(new Uri(url), c).ConfigureAwait(false);
        }
Esempio n. 12
0
        private async void SolveRouteButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Create a new route task using the San Diego route service URI.
                RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

                // Get the default parameters from the route task (defined with the service).
                RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

                // Make some changes to the default parameters.
                routeParams.ReturnStops      = true;
                routeParams.ReturnDirections = true;

                // Set the list of route stops that were defined at startup.
                routeParams.SetStops(_routeStops);

                // Solve for the best route between the stops and store the result.
                RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

                // Get the first (should be only) route from the result.
                Route firstRoute = solveRouteResult.Routes.First();

                // Get the route geometry (polyline).
                Polyline routePolyline = firstRoute.RouteGeometry;

                // Create a thick purple line symbol for the route.
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0);

                // Create a new graphic for the route geometry and add it to the graphics overlay.
                Graphic routeGraphic = new Graphic(routePolyline, routeSymbol)
                {
                    ZIndex = 0
                };
                _routeGraphicsOverlay.Graphics.Add(routeGraphic);

                // Get a list of directions for the route and display it in the list box.
                _directionsList = firstRoute.DirectionManeuvers;

                // Enable the directions button.
                _directionsButton.Enabled = true;
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Esempio n. 13
0
        private async void AddTrafficLayer()
        {
            try
            {
                _routeService = new Uri("https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve");

                var route = await RouteTask.CreateAsync(_routeService);


                ArcGISMapImageLayer traffic = new ArcGISMapImageLayer(new Uri(_trafficLayerURL));
                MyMapView.Map.OperationalLayers.Add(traffic);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");
            }
        }
Esempio n. 14
0
        private async void SolveRouteClick(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            try
            {
                // Create a new route task using the San Diego route service URI
                RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

                // Get the default parameters from the route task (defined with the service)
                RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

                // Make some changes to the default parameters
                routeParams.ReturnStops      = true;
                routeParams.ReturnDirections = true;

                // Set the list of route stops that were defined at startup
                routeParams.SetStops(_routeStops);

                // Solve for the best route between the stops and store the result
                RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

                // Get the first (should be only) route from the result
                Route firstRoute = solveRouteResult.Routes.First();

                // Get the route geometry (polyline)
                Polyline routePolyline = firstRoute.RouteGeometry;

                // Create a thick purple line symbol for the route
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0);

                // Create a new graphic for the route geometry and add it to the graphics overlay
                Graphic routeGraphic = new Graphic(routePolyline, routeSymbol)
                {
                    ZIndex = 0
                };
                _routeGraphicsOverlay.Graphics.Add(routeGraphic);

                // Get a list of directions for the route and display it in the list box
                IReadOnlyList <DirectionManeuver> directionsList = firstRoute.DirectionManeuvers;
                DirectionsListBox.ItemsSource = directionsList;
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error").ShowAsync();
            }
        }
Esempio n. 15
0
        private async void SolveRouteClick(object sender, EventArgs e)
        {
            try
            {
                // Create a new route task using the San Diego route service URI
                RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

                // Get the default parameters from the route task (defined with the service)
                RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

                // Make some changes to the default parameters
                routeParams.ReturnStops      = true;
                routeParams.ReturnDirections = true;

                // Set the list of route stops that were defined at startup
                routeParams.SetStops(_routeStops);

                // Solve for the best route between the stops and store the result
                RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

                // Get the first (should be only) route from the result
                Route firstRoute = solveRouteResult.Routes.First();

                // Get the route geometry (polyline)
                Polyline routePolyline = firstRoute.RouteGeometry;

                // Create a thick purple line symbol for the route
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0);

                // Create a new graphic for the route geometry and add it to the graphics overlay
                Graphic routeGraphic = new Graphic(routePolyline, routeSymbol)
                {
                    ZIndex = 0
                };
                _routeGraphicsOverlay.Graphics.Add(routeGraphic);

                // Get a list of directions for the route and display it in the list box
                CreateDirectionsDialog(firstRoute.DirectionManeuvers.Select(d => d.DirectionText));
                _showHideDirectionsButton.Enabled = true;
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }
Esempio n. 16
0
        private async void Initialize()
        {
            // Create and add the map.
            _mapView.Map = new Map(Basemap.CreateImagery());

            try
            {
                // Configure location display.
                _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter;
                await _mapView.LocationDisplay.DataSource.StartAsync();

                _mapView.LocationDisplay.IsEnabled = true;

                // Enable authentication.
                SetOAuthInfo();

                // Create the route task.
                _routeTask = await RouteTask.CreateAsync(new System.Uri("https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"));

                // Create route display overlay and symbology.
                _routeOverlay = new GraphicsOverlay();
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Yellow, 1);
                _routeOverlay.Renderer = new SimpleRenderer(routeSymbol);

                // Create stop display overlay.
                _stopsOverlay = new GraphicsOverlay();

                // Add the overlays to the map.
                _mapView.GraphicsOverlays.Add(_routeOverlay);
                _mapView.GraphicsOverlays.Add(_stopsOverlay);

                // Wait for the user to place stops.
                _mapView.GeoViewTapped += MapView_GeoViewTapped;

                // Updat the help text.
                _helpLabel.Text = "Tap to set a start point";
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", "Failed to start sample", (IUIAlertViewDelegate)null, "OK", null).Show();
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
        private async void Initialize()
        {
            try
            {
                // Update interface state.
                UpdateInterfaceState(SampleState.NotReady);

                // Create the map with a basemap.
                Map sampleMap = new Map(BasemapStyle.ArcGISTopographic);
                sampleMap.InitialViewpoint = new Viewpoint(32.7157, -117.1611, 1e5);
                MyMapView.Map = sampleMap;

                // Create the graphics overlays. These will manage rendering of route, direction, stop, and barrier graphics.
                _routeOverlay    = new GraphicsOverlay();
                _stopsOverlay    = new GraphicsOverlay();
                _barriersOverlay = new GraphicsOverlay();

                // Add graphics overlays to the map view.
                MyMapView.GraphicsOverlays.Add(_routeOverlay);
                MyMapView.GraphicsOverlays.Add(_stopsOverlay);
                MyMapView.GraphicsOverlays.Add(_barriersOverlay);

                // Create and initialize the route task.
                _routeTask = await RouteTask.CreateAsync(new Uri(RouteServiceUrl));

                // Get the route parameters from the route task.
                _routeParameters = await _routeTask.CreateDefaultParametersAsync();

                // Prepare symbols.
                _routeSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _barrierSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Red, null);

                // Enable the UI.
                UpdateInterfaceState(SampleState.Ready);
            }
            catch (Exception e)
            {
                UpdateInterfaceState(SampleState.NotReady);
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't load sample", "Couldn't start the sample. See the debug output for detail.");
            }
        }
Esempio n. 18
0
        public static async Task <RouteResult> LoadRouter(MapView mapView)
        {
            var routeSourceUri = new Uri("https://gis.tamu.edu/arcgis/rest/services/Routing/20201128/NAServer/Route");
            var routeTask      = await RouteTask.CreateAsync(routeSourceUri);

            // get the default route parameters
            var routeParams = await routeTask.CreateDefaultParametersAsync();

            // explicitly set values for some params
            routeParams.ReturnDirections = true;
            routeParams.ReturnRoutes     = true;
            if (mapView.SpatialReference != null)
            {
                routeParams.OutputSpatialReference = mapView.SpatialReference;
            }

            // create a Stop for my location
            var curLoc = await SpatialHelper.GetCurrentLocation();

            var myLocation = new MapPoint(curLoc.Value.Longitude, curLoc.Value.Latitude, SpatialReferences.Wgs84);
            var stop1      = new Stop(myLocation);

            // create a Stop for your location
            var yourLocation = new MapPoint(-96.34131, 30.61247, SpatialReferences.Wgs84);
            var stop2        = new Stop(yourLocation);

            // assign the stops to the route parameters
            var stopPoints = new List <Stop> {
                stop1, stop2
            };

            routeParams.SetStops(stopPoints);

            try
            {
                return(await routeTask.SolveRouteAsync(routeParams));
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Returns a route between the specified stops.
        /// </summary>
        /// <param name="stops">The stops on the route.</param>
        /// <returns></returns>
        public async Task <SolveRouteResult> SolveRouteAsync(MapPoint from, MapPoint to)
        {
            RouteTask       routeTask       = null;
            RouteParameters routeParameters = null;
            RouteResult     routeResult     = null;

            try
            {
                // Ensure the sample data is ready to go
                await DataManager.EnsureDataPresent();

                // Create a new route using the offline database
                routeTask = await RouteTask.CreateAsync(DataManager.GetDataFolder(_database), _networkName);

                // Configure the route and set the stops
                routeParameters = await routeTask.CreateDefaultParametersAsync();

                routeParameters.SetStops(new[] { new Stop(from), new Stop(to) });
                routeParameters.ReturnStops             = true;
                routeParameters.ReturnDirections        = true;
                routeParameters.RouteShapeType          = RouteShapeType.TrueShapeWithMeasures;
                routeParameters.OutputSpatialReference  = SpatialReferences.Wgs84;
                routeParameters.DirectionsDistanceUnits = UnitSystem.Metric;
                routeParameters.StartTime = DateTime.UtcNow;

                // Solve the route
                routeResult = await routeTask.SolveRouteAsync(routeParameters);
            }
            catch (Exception ex)
            {
                if (!(ex is ArcGISWebException web && web.Details.FirstOrDefault()?.Contains("Unlocated") == true))
                {
                    // There was some other error.
                    throw;
                }
            }

            return(new SolveRouteResult {
                Route = routeResult, Task = routeTask, Parameters = routeParameters
            });
        }
        /// <summary>
        /// Returns a route between the specified stops.
        /// </summary>
        /// <param name="stops">The stops on the route.</param>
        /// <returns></returns>
        public async Task <SolveRouteResult> SolveRouteAsync(MapPoint from, MapPoint to)
        {
            RouteTask       routeTask       = null;
            RouteParameters routeParameters = null;
            RouteResult     routeResult     = null;

            try
            {
                // Create a new route using the onling routing service
                routeTask = await RouteTask.CreateAsync(s_routeService, _credential);

                // Configure the route and set the stops
                routeParameters = await routeTask.CreateDefaultParametersAsync();

                routeParameters.SetStops(new[] { new Stop(from), new Stop(to) });
                routeParameters.ReturnStops             = true;
                routeParameters.ReturnDirections        = true;
                routeParameters.RouteShapeType          = RouteShapeType.TrueShapeWithMeasures;
                routeParameters.OutputSpatialReference  = SpatialReferences.Wgs84;
                routeParameters.DirectionsDistanceUnits = UnitSystem.Metric;
                routeParameters.StartTime = DateTime.UtcNow;

                // Solve the route
                routeResult = await routeTask.SolveRouteAsync(routeParameters);
            }
            catch (ArcGISWebException ex)
            {
                // Any error other than failure to locate is rethrown
                if (ex.Details.FirstOrDefault()?.Contains("Unlocated") != true)
                {
                    throw ex;
                }
            }

            return(new SolveRouteResult {
                Route = routeResult, Task = routeTask, Parameters = routeParameters
            });
        }
        /// <summary>
        /// Solves routing problem for given input parameters
        /// </summary>
        /// <returns></returns>
        public async Task <RouteUtilityResult> Solve()
        {
            routeTask = (routeTask) ?? await RouteTask.CreateAsync(RouteServiceUri);

            var routInfo = routeTask.RouteTaskInfo;

            // get the default route parameters
            routeParams = (routeParams) ?? await routeTask.CreateDefaultParametersAsync();

            // explicitly set values for some params
            // routeParams.ReturnDirections = true;
            // routeParams.ReturnRoutes = true;
            routeParams.OutputSpatialReference = SpatialRef;

            routeParams.SetStops(stopPoints);
            routeParams.SetPointBarriers(pointBarriers);
            var routeResult = await routeTask.SolveRouteAsync(routeParams);

            return(new RouteUtilityResult
            {
                RouteName = routeResult.Routes[0].RouteName,
                TotalTime = routeResult.Routes[0].TotalTime
            });
        }
Esempio n. 22
0
        private async void Initialize()
        {
            //Exercise 1: Create new Map with basemap and initial location
            myMap = new Map(Basemap.CreateNationalGeographic());
            //Exercise 1: Assign the map to the MapView
            mapView.Map = myMap;



            //Exercise 3: Add mobile map package to the map
            var mmpk = await MobileMapPackage.OpenAsync(MMPK_PATH);

            if (mmpk.Maps.Count >= 0)
            {
                myMap = mmpk.Maps[0];
                //Exercise 3: Mobile map package does not contain a basemap so must add one.
                myMap.Basemap = Basemap.CreateNationalGeographic();
                mapView.Map   = myMap;
            }
            mapView.GraphicsOverlays.Add(bufferAndQueryMapGraphics);
            mapView.GraphicsOverlays.Add(mapRouteGraphics);

            Uri             routeServiceUri = new Uri("http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World");
            TokenCredential credentials     = await AuthenticationManager.Current.GenerateCredentialAsync(routeServiceUri, "username", "password");

            routeTask = await RouteTask.CreateAsync(routeServiceUri, credentials);

            try
            {
                routeParameters = await routeTask.GenerateDefaultParametersAsync();
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
        }
        private async void Initialize()
        {
            try
            {
                // Create the map view.
                _myMapView.Map = new Map(BasemapStyle.ArcGISNavigation);

                // Create the route task, using the routing service.
                _routeTask = await RouteTask.CreateAsync(_networkGeodatabasePath, "Streets_ND");

                // Get the default route parameters.
                _routeParams = await _routeTask.CreateDefaultParametersAsync();

                // Explicitly set values for parameters.
                _routeParams.ReturnDirections       = true;
                _routeParams.ReturnStops            = true;
                _routeParams.ReturnRoutes           = true;
                _routeParams.OutputSpatialReference = SpatialReferences.Wgs84;

                // Create stops for each location.
                Stop stop1 = new Stop(_conventionCenter)
                {
                    Name = "San Diego Convention Center"
                };
                Stop stop2 = new Stop(_aerospaceMuseum)
                {
                    Name = "RH Fleet Aerospace Museum"
                };

                // Assign the stops to the route parameters.
                List <Stop> stopPoints = new List <Stop> {
                    stop1, stop2
                };
                _routeParams.SetStops(stopPoints);

                // Get the route results.
                _routeResult = await _routeTask.SolveRouteAsync(_routeParams);

                _route = _routeResult.Routes[0];

                // Add a graphics overlay for the route graphics.
                _myMapView.GraphicsOverlays.Add(new GraphicsOverlay());

                // Add graphics for the stops.
                SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20);
                _myMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol));
                _myMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol));

                // Create a graphic (with a dashed line symbol) to represent the route.
                _routeAheadGraphic = new Graphic(_route.RouteGeometry)
                {
                    Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5)
                };

                // Create a graphic (solid) to represent the route that's been traveled (initially empty).
                _routeTraveledGraphic = new Graphic {
                    Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3)
                };

                // Add the route graphics to the map view.
                _myMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic);
                _myMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic);

                // Set the map viewpoint to show the entire route.
                await _myMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100);

                // Enable the navigation button.
                _navigateButton.Enabled = true;
            }
            catch (Exception e)
            {
                new UIAlertView("Error", e.Message, (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Esempio n. 24
0
        private async Task ProcessRouteRequest(MapPoint tappedPoint)
        {
            // Clear any existing overlays.
            _routeOverlay.Graphics.Clear();
            _myMapView.DismissCallout();

            // Return if there is no network available for routing.
            if (_networkDataset == null)
            {
                await ShowGeocodeResult(tappedPoint);

                return;
            }

            // Set the start point if it hasn't been set.
            if (_startPoint == null)
            {
                _startPoint = tappedPoint;

                await ShowGeocodeResult(tappedPoint);

                // Show the start point.
                _waypointOverlay.Graphics.Add(await GraphicForPoint(_startPoint));

                return;
            }

            if (_endPoint == null)
            {
                await ShowGeocodeResult(tappedPoint);

                // Show the end point.
                _endPoint = tappedPoint;
                _waypointOverlay.Graphics.Add(await GraphicForPoint(_endPoint));

                // Create the route task from the local network dataset.
                RouteTask routingTask = await RouteTask.CreateAsync(_networkDataset);

                // Configure route parameters for the route between the two tapped points.
                RouteParameters routingParameters = await routingTask.CreateDefaultParametersAsync();

                List <Stop> stops = new List <Stop> {
                    new Stop(_startPoint), new Stop(_endPoint)
                };
                routingParameters.SetStops(stops);

                // Get the first route result.
                RouteResult result = await routingTask.SolveRouteAsync(routingParameters);

                Route firstRoute = result.Routes.First();

                // Show the route on the map. Note that symbology for the graphics overlay is defined in Initialize().
                Polyline routeLine = firstRoute.RouteGeometry;
                _routeOverlay.Graphics.Add(new Graphic(routeLine));

                return;
            }

            // Reset graphics and route.
            _routeOverlay.Graphics.Clear();
            _waypointOverlay.Graphics.Clear();
            _startPoint = null;
            _endPoint   = null;
        }
        private async void Initialize()
        {
            try
            {
                // Get the paths to resources used by the sample.
                string basemapTilePath        = DataManager.GetDataFolder("567e14f3420d40c5a206e5c0284cf8fc", "streetmap_SD.tpk");
                string networkGeodatabasePath = DataManager.GetDataFolder("567e14f3420d40c5a206e5c0284cf8fc", "sandiego.geodatabase");

                // Create the tile cache representing the offline basemap.
                TileCache tiledBasemapCache = new TileCache(basemapTilePath);

                // Create a tiled layer to display the offline tiles.
                ArcGISTiledLayer offlineTiledLayer = new ArcGISTiledLayer(tiledBasemapCache);

                // Create a basemap based on the tile layer.
                Basemap offlineBasemap = new Basemap(offlineTiledLayer);

                // Create a new map with the offline basemap.
                Map theMap = new Map(offlineBasemap);

                // Set the initial viewpoint to show the routable area.
                theMap.InitialViewpoint = new Viewpoint(_routableArea);

                // Show the map in the map view.
                _myMapView.Map = theMap;

                // Create overlays for displaying the stops and the calculated route.
                _stopsOverlay = new GraphicsOverlay();
                _routeOverlay = new GraphicsOverlay();

                // Create a symbol and renderer for symbolizing the calculated route.
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Blue, 2);
                _routeOverlay.Renderer = new SimpleRenderer(routeSymbol);

                // Add the stops and route overlays to the map.
                _myMapView.GraphicsOverlays.Add(_stopsOverlay);
                _myMapView.GraphicsOverlays.Add(_routeOverlay);

                // Create the route task, referring to the offline geodatabase with the street network.
                _offlineRouteTask = await RouteTask.CreateAsync(networkGeodatabasePath, "Streets_ND");

                // Get the list of available travel modes.
                _availableTravelModes = _offlineRouteTask.RouteTaskInfo.TravelModes.ToList();

                // Update the UI with the travel modes list.
                ArrayAdapter <string> spinnerListAdapter = new ArrayAdapter <string>(this,
                                                                                     Android.Resource.Layout.SimpleSpinnerItem, _availableTravelModes.Select(travelMode => travelMode.Name).ToArray());
                _travelModeSpinner.Adapter = spinnerListAdapter;
                _travelModeSpinner.SetSelection(0);

                // Create the default parameters.
                _offlineRouteParameters = await _offlineRouteTask.CreateDefaultParametersAsync();

                // Display the extent of the road network on the map.
                DisplayBoundaryMarker();

                // Now that the sample is ready, hook up the tapped and hover events.
                _myMapView.GeoViewTapped        += MapView_Tapped;
                _travelModeSpinner.ItemSelected += TravelMode_SelectionChanged;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                ShowMessage("Couldn't start sample", "There was a problem starting the sample. See debug output for details.");
            }
        }
Esempio n. 26
0
 public static async Task InitializeAsync(Credential?credential)
 {
     _routeTask = await RouteTask.CreateAsync(new Uri(ArcGISOnlineServices.WorldRoutingServiceUri), credential).ConfigureAwait(false);
 }
        async void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            // Assign the map to the MapView.
            MainMapView.Map = new Map(BasemapStyle.ArcGISNavigation);
            await MainMapView.Map.LoadAsync();

            //MapPoint mapCenterPoint = new MapPoint(, SpatialReferences.WebMercator);
            await MainMapView.SetViewpointAsync(new Viewpoint(52.0135053, 4.3367553, 72223.819286));

            // Create the route task, using the online routing service.
            RouteTask routeTask = await RouteTask.CreateAsync(_routingUri);

            // Get the default route parameters.
            RouteParameters routeParams = await routeTask.CreateDefaultParametersAsync();

            // Explicitly set values for parameters.
            routeParams.ReturnDirections       = true;
            routeParams.ReturnStops            = true;
            routeParams.ReturnRoutes           = true;
            routeParams.OutputSpatialReference = SpatialReferences.Wgs84;

            // Create stops for each location.
            Stop stop1 = new Stop(_conventionCenter)
            {
                Name = "Delft Netherlands"
            };
            Stop stop2 = new Stop(_memorial)
            {
                Name = "Rotterdam Netherlands"
            };
            //Stop stop3 = new Stop(_aerospaceMuseum) { Name = "Amsterdam Netherlands" };

            // Assign the stops to the route parameters.
            List <Stop> stopPoints = new List <Stop> {
                stop1, stop2
            };

            routeParams.SetStops(stopPoints);

            // Get the route results.
            _routeResult = await routeTask.SolveRouteAsync(routeParams);

            _route = _routeResult.Routes[0];

            // Add a graphics overlay for the route graphics.
            MainMapView.GraphicsOverlays.Add(new GraphicsOverlay());

            // Add graphics for the stops.
            SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20);

            MainMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol));
            MainMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_memorial, stopSymbol));
            //MainMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol));

            // Create a graphic (with a dashed line symbol) to represent the route.
            _routeAheadGraphic = new Graphic(_route.RouteGeometry)
            {
                Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5)
            };

            // Create a graphic (solid) to represent the route that's been traveled (initially empty).
            _routeTraveledGraphic = new Graphic {
                Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3)
            };

            // Add the route graphics to the map view.
            MainMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic);
            MainMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic);

            // Set the map viewpoint to show the entire route.
            await MainMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100);

            // Enable the navigation button.
            StartNavigationButton.IsEnabled = true;
        }
Esempio n. 28
0
        private async void SolveRouteClick(object sender, EventArgs e)
        {
            try
            {
                // Register a portal that uses OAuth authentication with the AuthenticationManager
                Esri.ArcGISRuntime.Security.ServerInfo serverInfo = new ServerInfo(new Uri("https://www.arcgis.com/sharing/rest"));
                serverInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials;
                serverInfo.OAuthClientInfo         = new OAuthClientInfo
                {
                    ClientId     = ClientId,
                    ClientSecret = ClientSecret,
                    RedirectUri  = new Uri(RedirectURI)
                };


                AuthenticationManager.Current.RegisterServer(serverInfo);
                // Create a new route task using the San Diego route service URI
                RouteTask solveRouteTask = await RouteTask.CreateAsync(_sanDiegoRouteServiceUri);

                // Get the default parameters from the route task (defined with the service)
                RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

                routeParams.PreserveLastStop = false;
                routeParams.DirectionsStyle  = DirectionsStyle.Navigation;

                //TravelMode travel = new TravelMode();
                var travelModes = solveRouteTask.RouteTaskInfo.TravelModes.ToList();
                // Make some changes to the default parameters
                routeParams.ReturnStops             = true;
                routeParams.ReturnDirections        = true;
                routeParams.FindBestSequence        = true;
                routeParams.DirectionsDistanceUnits = Esri.ArcGISRuntime.UnitSystem.Imperial;

                // Set the list of route stops that were defined at startup
                routeParams.SetStops(_routeStops);

                // Solve for the best route between the stops and store the result
                RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

                // Get the first (should be only) route from the result
                var   min        = solveRouteResult.Routes.Min(x => x.TotalLength);
                Route firstRoute = solveRouteResult.Routes.FirstOrDefault(x => x.TotalLength == min);

                // Get the route geometry (polyline)
                Polyline routePolyline = firstRoute.RouteGeometry;

                // Create a thick purple line symbol for the route
                SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Purple, 8.0);

                // Create a new graphic for the route geometry and add it to the graphics overlay
                Graphic routeGraphic = new Graphic(routePolyline, routeSymbol)
                {
                    ZIndex = 0
                };
                _routeGraphicsOverlay.Graphics.Add(routeGraphic);

                // Get a list of directions for the route and display it in the list box
                DirectionsListBox.ItemsSource = firstRoute.DirectionManeuvers.Select(direction => direction.DirectionText);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
Esempio n. 29
0
        private async void Initialize()
        {
            try
            {
                // Add event handler for when this sample is unloaded.
                Unloaded += SampleUnloaded;

                // Create the map view.
                MyMapView.Map = new Map(Basemap.CreateNavigationVector());

                // Create the route task, using the online routing service.
                RouteTask routeTask = await RouteTask.CreateAsync(_routingUri);

                // Get the default route parameters.
                RouteParameters routeParams = await routeTask.CreateDefaultParametersAsync();

                // Explicitly set values for parameters.
                routeParams.ReturnDirections       = true;
                routeParams.ReturnStops            = true;
                routeParams.ReturnRoutes           = true;
                routeParams.OutputSpatialReference = SpatialReferences.Wgs84;

                // Create stops for each location.
                Stop stop1 = new Stop(_conventionCenter)
                {
                    Name = "San Diego Convention Center"
                };
                Stop stop2 = new Stop(_memorial)
                {
                    Name = "USS San Diego Memorial"
                };
                Stop stop3 = new Stop(_aerospaceMuseum)
                {
                    Name = "RH Fleet Aerospace Museum"
                };

                // Assign the stops to the route parameters.
                List <Stop> stopPoints = new List <Stop> {
                    stop1, stop2, stop3
                };
                routeParams.SetStops(stopPoints);

                // Get the route results.
                _routeResult = await routeTask.SolveRouteAsync(routeParams);

                _route = _routeResult.Routes[0];

                // Add a graphics overlay for the route graphics.
                MyMapView.GraphicsOverlays.Add(new GraphicsOverlay());

                // Add graphics for the stops.
                SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, Color.OrangeRed, 20);
                MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_conventionCenter, stopSymbol));
                MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_memorial, stopSymbol));
                MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(_aerospaceMuseum, stopSymbol));

                // Create a graphic (with a dashed line symbol) to represent the route.
                _routeAheadGraphic = new Graphic(_route.RouteGeometry)
                {
                    Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.BlueViolet, 5)
                };

                // Create a graphic (solid) to represent the route that's been traveled (initially empty).
                _routeTraveledGraphic = new Graphic {
                    Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.LightBlue, 3)
                };

                // Add the route graphics to the map view.
                MyMapView.GraphicsOverlays[0].Graphics.Add(_routeAheadGraphic);
                MyMapView.GraphicsOverlays[0].Graphics.Add(_routeTraveledGraphic);

                // Set the map viewpoint to show the entire route.
                await MyMapView.SetViewpointGeometryAsync(_route.RouteGeometry, 100);

                // Enable the navigation button.
                StartNavigationButton.IsEnabled = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error");
            }
        }
        private async void Initialize()
        {
            // Create and add the map.
            MyMapView.Map = new Map(BasemapStyle.ArcGISImageryStandard);

            MyMapView.PropertyChanged += async(o, e) =>
            {
                // Start the location display on the mapview.
                try
                {
                    // Permission request only needed on Android.
                    if (e.PropertyName == nameof(MyMapView.LocationDisplay) && MyMapView.LocationDisplay != null)
                    {
#if XAMARIN_ANDROID
                        // See implementation in MainActivity.cs in the Android platform project.
                        bool permissionGranted = await MainActivity.Instance.AskForLocationPermission();

                        if (!permissionGranted)
                        {
                            throw new Exception("Location permission not granted.");
                        }
#endif

                        MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter;
                        await MyMapView.LocationDisplay.DataSource.StartAsync();

                        MyMapView.LocationDisplay.IsEnabled = true;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    await Application.Current.MainPage.DisplayAlert("Couldn't start location", ex.Message, "OK");
                }
            };

            // Enable authentication.
            SetOAuthInfo();
            var credential = await AuthenticationManager.Current.GenerateCredentialAsync(_routingUri);

            AuthenticationManager.Current.AddCredential(credential);

            try
            {
                // Create the route task.
                _routeTask = await RouteTask.CreateAsync(_routingUri);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Failed to start sample", "OK");

                Debug.WriteLine(ex.Message);
            }

            // Create route display overlay and symbology.
            _routeOverlay = new GraphicsOverlay();
            SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Yellow, 1);
            _routeOverlay.Renderer = new SimpleRenderer(routeSymbol);

            // Create stop display overlay.
            _stopsOverlay = new GraphicsOverlay();

            // Add the overlays to the map.
            MyMapView.GraphicsOverlays.Add(_routeOverlay);
            MyMapView.GraphicsOverlays.Add(_stopsOverlay);

            // Wait for the user to place stops.
            MyMapView.GeoViewTapped += MapView_GeoViewTapped;

            // Update the help text.
            HelpLabel.Text = "Tap to set a start point";
        }