This is a migrated thread and some comments may be shown as answers.

Possible to display route directions and show traffic?

4 Answers 135 Views
Map
This is a migrated thread and some comments may be shown as answers.
Rod Yager
Top achievements
Rank 1
Rod Yager asked on 03 Nov 2010, 07:36 PM
Are either of these possible? I currently do both right now using MS VEMap AJAX mapcontrol (Virtual Earth).

4 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 08 Nov 2010, 05:47 PM
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
0
Rod Yager
Top achievements
Rank 1
answered on 10 Nov 2010, 03:05 PM
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
0
Rod Yager
Top achievements
Rank 1
answered on 12 Nov 2010, 01:41 AM

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("");
            }


0
Accepted
Andrey
Telerik team
answered on 12 Nov 2010, 04:32 PM
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
Tags
Map
Asked by
Rod Yager
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Rod Yager
Top achievements
Rank 1
Share this question
or