Exemple #1
0
        public List <MyWaypoint> CreateRoute(MyWaypoint startPoint, MyWaypoint endPoint)
        {
            // create route from waypointString
            RouteRequest routeRequest = new RouteRequest();

            // Set the credentials using a valid Bing Maps key
            routeRequest.Credentials = new BingRouteService.Credentials();
            routeRequest.Credentials.ApplicationId = m_bingMapKey;

            // tell them that we want points along the route
            routeRequest.Options = new RouteOptions();
            routeRequest.Options.RoutePathType = RoutePathType.Points;

            //Parse user data to create array of waypoints
            BingRouteService.Waypoint[] waypoints = new BingRouteService.Waypoint[2];

            BingRouteService.Waypoint point1    = new BingRouteService.Waypoint();
            BingRouteService.Location location1 = new BingRouteService.Location();
            location1.Latitude  = startPoint.Latitude;
            location1.Longitude = startPoint.Longitude;
            point1.Location     = location1;
            point1.Description  = "Start";
            waypoints[0]        = point1;

            BingRouteService.Waypoint point2    = new BingRouteService.Waypoint();
            BingRouteService.Location location2 = new BingRouteService.Location();
            location2.Latitude  = endPoint.Latitude;
            location2.Longitude = endPoint.Longitude;
            point2.Location     = location2;
            point2.Description  = "End";
            waypoints[1]        = point2;

            routeRequest.Waypoints = waypoints;

            // Make the calculate route request
            RouteServiceClient routeService  = new RouteServiceClient("BasicHttpBinding_IRouteService");
            RouteResponse      routeResponse = routeService.CalculateRoute(routeRequest);

            // pull out the lat/lon values
            List <MyWaypoint> returnPoints = new List <MyWaypoint>();

            if (routeResponse.Result.Legs.Length > 0)
            {
                //MessageBox.Show("Distance: " + routeResponse.Result.Summary.Distance.ToString()
                //    + " Time: " + routeResponse.Result.Summary.TimeInSeconds.ToString());
                foreach (BingRouteService.Location thisPt in routeResponse.Result.RoutePath.Points)
                {
                    MyWaypoint thisPoint = new MyWaypoint();

                    thisPoint.Latitude  = thisPt.Latitude;
                    thisPoint.Longitude = thisPt.Longitude;
                    //thisPoint.Altitude = GetAltitude(thisPoint.Latitude, thisPoint.Longitude);
                    thisPoint.Altitude = 0.0;

                    returnPoints.Add(thisPoint);
                }
            }

            return(returnPoints);
        }
Exemple #2
0
 private BingRouteService.Waypoint ConvertGeocodeResultToWaypoint(BingGeocodeService.GeocodeResult result)
 {
     BingRouteService.Waypoint waypoint = new BingRouteService.Waypoint();
     waypoint.Description = result.DisplayName;
     waypoint.Location    = new BingRouteService.Location()
     {
         Latitude  = result.Locations[0].Latitude,
         Longitude = result.Locations[0].Longitude
     };
     return(waypoint);
 }