Example #1
0
        public void GetRouteDirections()
        {
            var am  = new AzureMapsToolkit.AzureMapsServices(_KEY);
            var req = new RouteRequestDirections
            {
                Query = "52.50931,13.42936:52.50274,13.43872"
            };
            var directions = am.GetRouteDirections(req).Result;

            Assert.Null(directions.Error);
            Assert.NotNull(directions.Result);
        }
Example #2
0
        public void GetRouteDirectionsError()
        {
            var am  = new AzureMapsToolkit.AzureMapsServices(_KEY);
            var req = new RouteRequestDirections
            {
                Query             = "52.50931,13.42936:52.50274,13.43872",
                VehicleEngineType = VehicleEngineType.Combustion
            };
            var directions = am.GetRouteDirections(req).Result;

            Assert.NotNull(directions.Error);
        }
Example #3
0
        public async Task GetRouteDirectionsError()
        {
            var am  = new AzureMapsToolkit.AzureMapsServices(_KEY);
            var req = new RouteRequestDirections
            {
                Query             = "52.50931,13.42936:52.50274,13.43872f", // intentially error
                VehicleEngineType = VehicleEngineType.Combustion,
                InstructionsType  = RouteInstructionsType.text
            };
            var directions = await am.GetRouteDirections(req);

            Assert.NotNull(directions.Error);
        }
Example #4
0
        public async Task GetRouteDirections()
        {
            var am  = new AzureMapsToolkit.AzureMapsServices(_KEY);
            var req = new RouteRequestDirections
            {
                //Query = "52.50931,13.42936:52.50274,13.43872"
                Query = "62.469026,16.696987:62.397051,17.363892",
                Avoid = Avoid.tollRoads
            };
            var directions = await am.GetRouteDirections(req);

            Assert.Null(directions.Error);
            Assert.NotNull(directions.Result);
        }
Example #5
0
        static void GetRoute(StateEnum newState)
        {
            // Set the state to ready, until the new route arrives.
            state = StateEnum.ready;

            var req = new RouteRequestDirections
            {
                Query = $"{currentLat},{currentLon}:{destinationLat},{destinationLon}"
            };
            var directions = azureMapsServices.GetRouteDirections(req).Result;

            if (directions.Error != null || directions.Result == null)
            {
                // Handle any error.
                redMessage("Failed to find map route");
            }
            else
            {
                int nPoints = directions.Result.Routes[0].Legs[0].Points.Length;
                greenMessage($"Route found. Number of points = {nPoints}");

                // Clear the path. Add two points for the start point and destination.
                path = new double[nPoints + 2, 2];
                int c = 0;

                // Start with the current location.
                path[c, 0] = currentLat;
                path[c, 1] = currentLon;
                ++c;

                // Retrieve the route and push the points onto the array.
                for (var n = 0; n < nPoints; n++)
                {
                    var x = directions.Result.Routes[0].Legs[0].Points[n].Latitude;
                    var y = directions.Result.Routes[0].Legs[0].Points[n].Longitude;
                    path[c, 0] = x;
                    path[c, 1] = y;
                    ++c;
                }

                // Finish with the destination.
                path[c, 0] = destinationLat;
                path[c, 1] = destinationLon;

                // Store the path length and time taken, to calculate the average speed.
                var meters    = directions.Result.Routes[0].Summary.LengthInMeters;
                var seconds   = directions.Result.Routes[0].Summary.TravelTimeInSeconds;
                var pathSpeed = meters / seconds;

                double distanceApartInMeters;
                double timeForOneSection;

                // Clear the time on path array. The path array is 1 less than the points array.
                timeOnPath = new double[nPoints + 1];

                // Calculate how much time is required for each section of the path.
                for (var t = 0; t < nPoints + 1; t++)
                {
                    // Calculate distance between the two path points, in meters.
                    distanceApartInMeters = DistanceInMeters(path[t, 0], path[t, 1], path[t + 1, 0], path[t + 1, 1]);

                    // Calculate the time for each section of the path.
                    timeForOneSection = distanceApartInMeters / pathSpeed;
                    timeOnPath[t]     = timeForOneSection;
                }
                truckOnSection             = 0;
                truckSectionsCompletedTime = 0;
                timeOnCurrentTask          = 0;

                // Update the state now the route has arrived. One of: enroute or returning.
                state = newState;
            }
        }
Example #6
0
        /// <summary>
        /// eturns a route between an origin and a destination, passing through waypoints if they are specified. The route will take into account factors such as current traffic and the typical road speeds on the requested day of the week and time of day.
        /// Information returned includes the distance, estimated travel time, and a representation of the route geometry.Additional routing information such as optimized waypoint order or turn by turn instructions is also available, depending on the options selected.
        /// Routing service provides a set of parameters for a detailed description of vehicle-specific Consumption Model.Please check Consumption Model for detailed explanation of the concepts and parameters involved.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="wayPoints"></param>
        /// <returns></returns>
        public virtual async Task <Response <RouteDirectionsResponse> > GetRouteDirections(RouteRequestDirections routeReq)
        {
            var res = await ExecuteRequest <RouteDirectionsResponse, RouteRequestDirections>
                          ("https://atlas.microsoft.com/route/directions/json", routeReq);

            return(res);
        }