Possible to display route directions and show traffic?

5 posts, 1 answers
  1. Rod Yager
    Rod Yager avatar
    79 posts
    Member since:
    May 2010

    Posted 03 Nov 2010 Link to this post

    Are either of these possible? I currently do both right now using MS VEMap AJAX mapcontrol (Virtual Earth).
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 08 Nov 2010 Link to this post

    Hi Rod Yager,

    You can show a route using the MapPolyline class, but it does not support built-in driving direction feature like to displaying arrows.
    We have the PITS issue for this feature.You can check when this feature will be available using the following link:
    http://www.telerik.com/support/pits.aspx#/public/silverlight/1121

    Also you can vote to speed up a development of this feature. One of the major criteria for priority of the feature development is a number of the customer's votes in PITS.

    All the best,
    Andrey Murzov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rod Yager
    Rod Yager avatar
    79 posts
    Member since:
    May 2010

    Posted 10 Nov 2010 Link to this post

    Thanks Andrey. So you don't have any sample code that iterates through the RouteLegs and compiles together the driving directions? In the RouteResponse.Result I can see Legs. In the those Legs I can see Intineraries with itineraryItems that have a text property with the directions in them.

    <VirtualEarth:Action>Bear</VirtualEarth:Action> <VirtualEarth:TurnDir>left</VirtualEarth:TurnDir> onto <VirtualEarth:RoadName>US-18 East / W Bluemound Rd</VirtualEarth:RoadName>

    Rod
  5. Rod Yager
    Rod Yager avatar
    79 posts
    Member since:
    May 2010

    Posted 11 Nov 2010 Link to this post

    For what it is worth, I wrote my own method to parse the directions. Hope this helps anyone that needs it. I plan on placing this into a layer on my map.

    StringBuilder sb = new StringBuilder();            
      
                foreach (RouteLeg leg in routeResponse.Result.Legs)
                {
                    if (leg.Itinerary.Count > 0)
                    {
                        int itemCount = 1;
                        sb.Append(itemCount.ToString() + ".");
      
                        foreach (ItineraryItem item in leg.Itinerary)
                        {                        
                            string[] directions = item.Text.Split('>');
                            foreach (string part in directions)
                            {
                                if (!part.StartsWith("<"))
                                {
                                    int posOfOpen = part.IndexOf("<");
                                    string newWords = string.Empty;
                                    if (posOfOpen >= 0)
                                    {
                                        newWords = part.Substring(0, posOfOpen);
                                        sb.Append(newWords);
                                    }
                                    else
                                    {
                                        sb.Append(part);
                                    }
                                }
                                  
                            }
      
                            itemCount += 1;
                            sb.AppendLine("");
                            if (itemCount <= leg.Itinerary.Count)
                            {
                                sb.Append(itemCount.ToString() + ".");
                            }                        
                        }
                    }
      
                    sb.AppendLine("");
                }


  6. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 12 Nov 2010 Link to this post

    Hi Rod Yager,

    The Text property of the ItineraryItem contains XML fragment with description. So I would recommend you to use standard .NET features to read and parse it. For example:

    // Load Driving direction to the text.
    StringBuilder sb = new StringBuilder();
      
    NameTable nt = new NameTable();
    XmlNamespaceManager mgr = new XmlNamespaceManager(nt);
    mgr.AddNamespace("VirtualEarth", "http://BingMaps");
      
    XmlParserContext pc = new XmlParserContext(nt, mgr, "", XmlSpace.Default);
      
    foreach (RouteLeg leg in routeResponse.Result.Legs)
    {
        foreach (ItineraryItem item in leg.Itinerary)
        {
            XmlReaderSettings xrs = new XmlReaderSettings();
            xrs.ConformanceLevel = ConformanceLevel.Fragment;
      
            XDocument doc = new XDocument(new XElement("root"));
            XElement root = doc.Descendants().First();
      
            using (StringReader fs = new StringReader(item.Text))
            {
                using (XmlReader xr = XmlReader.Create(fs, xrs, pc))
                {
                    while (xr.Read())
                    {
                        if (xr.NodeType == XmlNodeType.Element)
                        {
                            XElement description = XElement.Load(xr.ReadSubtree());
                            sb.Append(description.Value);
                            sb.Append(" ");
                        }
                    }
                }
            }
            sb.AppendLine(""); 
        }
        sb.AppendLine(""); 
    }
      
    this.drivingDirection.Text = sb.ToString();

    Using this approach you can easy add some additional processing for loaded XML elements if necessary.

    Greetings,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready