public void InitializeControlData(DirectionSteps directionSteps)
 {
     foreach (var step in directionSteps.Steps)
     {
         var mapdirectionStepControl = new MapDirectionStepControl { DataContext = step };
         stepsContainer.Children.Add(mapdirectionStepControl);
     }
     DataContext = directionSteps;
 }
Ejemplo n.º 2
0
 private static DirectionSteps ParseDirectionResults(string result)
 {
     DirectionSteps directionSteps = null;
     var xmlDoc = new XmlDocument {InnerXml = result};
     if (xmlDoc.HasChildNodes)
     {
         var directionsResponseNode = xmlDoc.SelectSingleNode("DirectionsResponse");
         if (directionsResponseNode != null)
         {
             var statusNode = directionsResponseNode.SelectSingleNode("status");
             if (statusNode != null && statusNode.InnerText.Equals("OK"))
             {
                 var legs = directionsResponseNode.SelectNodes("route/leg");
                 if (legs != null && legs.Count > 0)
                 {
                     directionSteps = new DirectionSteps();
                     foreach (XmlNode leg in legs)
                     {
                         int stepCount = 1;
                         var stepNodes = leg.SelectNodes("step");
                         var steps = new List<DirectionStep>();
                         foreach (XmlNode stepNode in stepNodes)
                         {
                             var directionStep = new DirectionStep();
                             directionStep.Index = stepCount++;
                             directionStep.Distance = stepNode.SelectSingleNode("distance/text").InnerText;
                             directionStep.Duration = stepNode.SelectSingleNode("duration/text").InnerText;
                             directionStep.Description = Regex.Replace(stepNode.SelectSingleNode("html_instructions").InnerText, "<[^<]+?>", "");
                             steps.Add(directionStep);
                         }
                         directionSteps.OriginAddress = leg.SelectSingleNode("start_address").InnerText;
                         directionSteps.DestinationAddress = leg.SelectSingleNode("end_address").InnerText;
                         directionSteps.TotalDistance = leg.SelectSingleNode("distance/text").InnerText;
                         directionSteps.TotalDuration = leg.SelectSingleNode("duration/text").InnerText;
                         directionSteps.Steps = steps;
                     }
                 }
             }
         }
     }
     return directionSteps;
 }