RouteGetDirections Method (UnitSystem, String, IAsyncDirectionsHandler) |
Namespace: Telogis.GeoBase.Routing
public Directions GetDirections( UnitSystem units, string culture, IAsyncDirectionsHandler handler )
Used to asynchronously supply natural-language directions as they are generated. IAsyncDirectionsHandler methods supported include OnDirectionsAppended(AsyncDirectionsEventArgs) which fires when a new direction is added to the Directions object; OnDirectionsClearUncommitted(AsyncDirectionsEventArgs) which fires when a direction is found to be incorrect clearing all uncommitted directions, OnDirectionsCommitted(AsyncDirectionsEventArgs) which fires when directions are confirmed as correct and commits all appended directions since the last commit, and OnDirectionsCompleted(AsyncDirectionsEventArgs) which fires when all directions have been generated and committed.
Related articles: Creating a Route, Using Directions.
class DirectionsHandler : IAsyncDirectionsHandler { #region IAsyncDirectionsHandler Members public void OnDirectionsAppended(AsyncDirectionsEventArgs args) { Console.WriteLine("OnDirectionsAppended"); DisplayDirectionsSoFar(args); Console.ReadKey(); } public void OnDirectionsCommitted(AsyncDirectionsEventArgs args) { // This will be called when all the directions in the list // args.Directions are confirmed to be correct Console.WriteLine("OnDirectionsCommitted"); DisplayDirectionsSoFar(args); } public void OnDirectionsClearUncommitted(AsyncDirectionsEventArgs args) { // This will be called when the last uncommitted directions instruction in // args.Directions is confirmed to be incorrect Console.WriteLine("OnDirectionsClearUncommitted"); DisplayDirectionsSoFar(args); } public void OnDirectionsCompleted(AsyncDirectionsEventArgs args) { // This will be called when all the directions for the route has been // confirmed as correct Console.WriteLine("That's all the directions!"); DisplayDirectionsSoFar(args); } private void DisplayDirectionsSoFar(AsyncDirectionsEventArgs args) { // List the directions that GetDirections is sure about for (int i = 0; i < args.UncommittedIndex; i++) { Console.WriteLine(" * " + args.Directions[i]); } // List the directions that GetDirections is unsure about (the rest of the directions) for (int i = args.UncommittedIndex; i < args.Directions.Count; i++) { Console.WriteLine(" " + args.Directions[i]); } } #endregion } Main() { Route route = new Route(); route.Start = new RouteStop(33.903187, -118.225697); route.AddStopAtEnd(new RouteStop(33.903457, -118.225756)); route.End = new RouteStop(33.903178, -118.225835); DirectionsHandler dh = new DirectionsHandler(); //r.GetDirections(); route.GetDirections(Telogis.GeoBase.Navigation.UnitSystem.Metric, "en-US", dh); }