Esempio n. 1
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. 2
0
        public static async Task SetViewpointToCurrentLocation(MapView mapView, GraphicsOverlay mapGraphics, Windows.Foundation.TypedEventHandler <Windows.Devices.Geolocation.Geolocator, Windows.Devices.Geolocation.PositionChangedEventArgs> PositionChangedHandler, bool zoomToLocation = true)
        {
            var currentLoc = await SpatialHelper.GetCurrentLocation();

            if (currentLoc.HasValue)
            {
                var currentLocPoint = CreateRouteStop(currentLoc.Value.Latitude, currentLoc.Value.Longitude, System.Drawing.Color.Red);
                currentLocPoint.Attributes.Add("id", "currentLocation");
                mapGraphics.Graphics.Add(currentLocPoint);
                if (zoomToLocation)
                {
                    await mapView.SetViewpointCenterAsync(currentLoc.Value.Latitude, currentLoc.Value.Longitude);

                    await mapView.SetViewpointScaleAsync(2000);
                }

                if (PositionChangedHandler != null)
                {
                    SpatialHelper.Geolocator.PositionChanged += PositionChangedHandler;
                }
            }
        }