Click here to Skip to main content
15,030,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm building a map that allows draw route from two location by using Bing Maps. However, I have a overlay on the route (for example: police, traffic jam...). So, I want to draw other route for two locations. Anyone can help me! Thanks for your time!

Code to draw a route from two locations:
C#
private void RouteServiceTest(Location from, Location to)
{
            var request = new RouteRequest
            {
                Options = new RouteOptions { RoutePathType = RoutePathType.Points },
                ExecutionOptions = new ExecutionOptions { SuppressFaults = true }
            };
            
            request.Waypoints = new ObservableCollection<Waypoint>
                                  {new Waypoint{ Location = from},
                                   new Waypoint {Location = to}
                                  };
            var client = new RouteServiceClient("BasicHttpBinding_IRouteService");
            client.CalculateRouteCompleted +=
                (o, args) =>
                {
                    if (args.Error == null)
                    {
                        var line = new MapPolyline
                        {
                            Locations = new LocationCollection(),
                            Stroke = (Brush)Application.Current.Resources["PhoneAccentBrush"],
                            StrokeThickness = 4

                        };
                        foreach (var point in args.Result.Result.RoutePath.Points)
                        {
                            line.Locations.Add(point);
                        }
                        map1.Children.Add(line);
                        map1.SetView(LocationRect.CreateLocationRect(line.Locations));
                        //mapMain.ZoomLevel = 2;
                    }
                };
            var pushpinMicrosft = new Microsoft.Phone.Controls.Maps.Pushpin
            {
                Content = "Microsoft",
                Location = from,
                Background = (Brush)Application.Current.Resources["PhoneAccentBrush"]
            };
            var pushpinGoogle = new Microsoft.Phone.Controls.Maps.Pushpin
            {
                Content = "Google",
                Location = to,
                Background = (Brush)Application.Current.Resources["PhoneAccentBrush"]
            };
            map1.Children.Add(pushpinMicrosft);
            map1.Children.Add(pushpinGoogle);
            map1.CredentialsProvider.GetCredentials(credentials =>
            {
                request.Credentials = credentials;
                client.CalculateRouteAsync(request);
            });
 }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900