private string CreateMajorRoutes(string locationString) { string results = ""; MajorRoutesRequest majorRoutesRequest = new MajorRoutesRequest(); // Set the credentials using a valid Bing Maps key majorRoutesRequest.Credentials = new RouteService.Credentials(); majorRoutesRequest.Credentials.ApplicationId = key; // Set the destination of the routes from major roads Waypoint endPoint = new Waypoint(); endPoint.Location = new RouteService.Location(); string[] digits = locationString.Split(','); endPoint.Location.Latitude = double.Parse(digits[0].Trim()); endPoint.Location.Longitude = double.Parse(digits[1].Trim()); endPoint.Description = "Location"; // Set the option to return full routes with directions MajorRoutesOptions options = new MajorRoutesOptions(); options.ReturnRoutes = true; majorRoutesRequest.Destination = endPoint; majorRoutesRequest.Options = options; // Make the route-from-major-roads request RouteServiceClient routeService = new RouteServiceClient(); // The result is an MajorRoutesResponse Object MajorRoutesResponse majorRoutesResponse = routeService.CalculateRoutesFromMajorRoads(majorRoutesRequest); Regex regex = new Regex("<[/a-zA-Z:]*>", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (majorRoutesResponse.StartingPoints.Length > 0) { StringBuilder directions = new StringBuilder(); for (int i = 0; i < majorRoutesResponse.StartingPoints.Length; i++) { directions.Append(String.Format("Coming from {1}\n", i + 1, majorRoutesResponse.StartingPoints[i].Description)); for (int j = 0; j < majorRoutesResponse.Routes[i].Legs[0].Itinerary.Length; j++) { //Strip tags string step = regex.Replace( majorRoutesResponse.Routes[i].Legs[0].Itinerary[j].Text, string.Empty); directions.Append(String.Format(" {0}. {1}\n", j + 1, step)); } } results = directions.ToString(); } else results = "No Routes found"; return results; }
private string CreateMajorRoutes(string locationString) { string results = ""; string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7"; MajorRoutesRequest majorRoutesRequest = new MajorRoutesRequest(); // Set the credentials using a valid Bing Maps key majorRoutesRequest.Credentials = new RouteService.Credentials(); majorRoutesRequest.Credentials.ApplicationId = key; // Set the destination of the routes from major roads Waypoint endPoint = new Waypoint(); endPoint.Location = new RouteService.Location(); string[] digits = locationString.Split(','); endPoint.Location.Latitude = double.Parse(digits[0].Trim()); endPoint.Location.Longitude = double.Parse(digits[1].Trim()); endPoint.Description = "Location"; // Set the option to return full routes with directions MajorRoutesOptions options = new MajorRoutesOptions(); options.ReturnRoutes = true; majorRoutesRequest.Destination = endPoint; majorRoutesRequest.Options = options; // Make the route-from-major-roads request RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService"); // The result is an MajorRoutesResponse Object MajorRoutesResponse majorRoutesResponse = routeService.CalculateRoutesFromMajorRoads(majorRoutesRequest); Regex regex = new Regex("<[/a-zA-Z:]*>", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (majorRoutesResponse.StartingPoints.Length > 0) { StringBuilder directions = new StringBuilder(); for (int i = 0; i < majorRoutesResponse.StartingPoints.Length; i++) { directions.Append(String.Format("Coming from {1}\n", i + 1, majorRoutesResponse.StartingPoints[i].Description)); for (int j = 0; j < majorRoutesResponse.Routes[i].Legs[0].Itinerary.Length; j++) { //Strip tags string step = regex.Replace( majorRoutesResponse.Routes[i].Legs[0].Itinerary[j].Text, string.Empty); directions.Append(String.Format(" {0}. {1}\n", j + 1, step)); } } results = directions.ToString(); } else { results = "No Routes found"; } return(results); }