Пример #1
0
        public static Route RefreshRoute(RouteLocation start, RouteLocation end, RouteDefinition route, bool reverseRoute)
        {
            RouteRestRequest request = new RouteRestRequest();

            request.Waypoints = new List<RestWaypoint>();
            request.Waypoints.Add(new RestWaypoint());

            request.ApplicationId = BingMapsApiKey;
            request.Waypoints[0].Location = new RestLocation();

            request.Waypoints[0].Location.Latitude = start.Location.Latitude;
            request.Waypoints[0].Location.Longitude = start.Location.Longitude;

            foreach (MobileSrc.Commuter.Shared.RouteLocation wayPoint in route.WayPoints)
            {
                request.Waypoints.Add(new RestWaypoint());
                request.Waypoints[request.Waypoints.Count - 1].Location = new RestLocation();
                request.Waypoints[request.Waypoints.Count - 1].Location.Latitude = wayPoint.Location.Latitude;
                request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = wayPoint.Location.Longitude;
            }

            request.Waypoints.Add(new RestWaypoint());
            request.Waypoints[request.Waypoints.Count - 1].Location = new RestLocation();
            request.Waypoints[request.Waypoints.Count - 1].Location.Latitude = end.Location.Latitude;
            request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = end.Location.Longitude;

            if (route.AvoidanceMeasures != RouteAvoid.None)
            {
                request.Avoid = route.AvoidanceMeasures;
            }

            if (reverseRoute)
            {
                System.Collections.Generic.List<RestWaypoint> reversed = new System.Collections.Generic.List<RestWaypoint>();

                for (int i = request.Waypoints.Count - 1; i >= 0; --i)
                {
                    reversed.Add(request.Waypoints[i]);
                }

                request.Waypoints = reversed;
            }

            request.Optimize = RouteOptimize.TimeWithTraffic;
            request.PathOutput = RoutePathOutput.Points;

            return request.Execute();
        }
Пример #2
0
        public static RouteLocation CreateRouteLocation(MobileSrc.Services.GeocodeServices.GeocodeResult result)
        {
            RouteLocation routeLoc = new RouteLocation();

            routeLoc.Location = new GpsLocation();
            routeLoc.Location.Latitude = result.Locations[0].Latitude;
            routeLoc.Location.Longitude = result.Locations[0].Longitude;
            routeLoc.Location.Altitude = result.Locations[0].Altitude;

            routeLoc.Address = result.Address.FormattedAddress;

            return routeLoc;
        }