2013-10-26 23 views
0

我有一個代碼,從Bing地圖,我解析它itinerery點retistsn XML。有趣的是,當我在視覺上展示時,我看到Bing的表現很奇怪。因此,它有時在沒有十字路口的直路上給我點數。這是我的應用程序的一個問題,因爲我得到的分數比我應該多。從Bing地圖解析XML考慮manouvertype

問題:我想消除點,其中標籤:ManouverType是keepStraight或continueRoute。

的XML這個樣子的

<ItineraryItem> 
<TravelMode>Driving</TravelMode> 
<TravelDistance>0.586</TravelDistance> 
<TravelDuration>66</TravelDuration> 
<ManeuverPoint> 
<Latitude>46.086102</Latitude> 
<Longitude>19.679518</Longitude> 
</ManeuverPoint> 
<Instruction maneuverType="EnterThenExitRoundabout">At roundabout, take 1st exit onto Ulica Bajnatska</Instruction> 
<CompassDirection>west</CompassDirection> 
<Detail> 
<ManeuverType>EnterRoundabout</ManeuverType> 
<StartPathIndex>2</StartPathIndex> 
<EndPathIndex>4</EndPathIndex> 
<CompassDegrees>208</CompassDegrees> 
<Mode>Driving</Mode> 
<PreviousEntityId>0</PreviousEntityId> 
<NextEntityId>0</NextEntityId> 
<RoadType>Arterial</RoadType> 
</Detail> 
<Detail> 
<ManeuverType>ExitRoundabout</ManeuverType> 
<StartPathIndex>4</StartPathIndex> 
<EndPathIndex>8</EndPathIndex> 
<Name>Ulica Bajnatska</Name> 
<CompassDegrees>250</CompassDegrees> 
<Mode>Driving</Mode> 
<PreviousEntityId>0</PreviousEntityId> 
<NextEntityId>0</NextEntityId> 
<RoadType>Arterial</RoadType> 
</Detail> 
... 

我的代碼看起來像這樣

public List<CGeoPoint> GetItin(CGeoPair latlongpair) 
    { 
     string RequestText = CreateRequest(latlongpair.GeoPoint1, latlongpair.GeoPoint2); 
     XmlDocument locationsResponse = MakeRequest(RequestText); 

     List<CGeoPoint> itin = new List<CGeoPoint>(); 

     XmlNodeList nList = locationsResponse.GetElementsByTagName("ManeuverPoint"); 

     foreach (XmlNode node in nList) 
     { 
      decimal d1 = decimal.Parse(node.ChildNodes[0].InnerText); 
      decimal d2 = decimal.Parse(node.ChildNodes[1].InnerText); 

      CGeoPoint ll = new CGeoPoint(d1, d2); 
      itin.Add(ll); 
     } 
     return itin; 
    } 

此代碼返回我的緯度和經度爲每個ItineraryItem

+0

請用語言標記問題('c#'也許)。 – laalto

回答

0

好吧,我解決了以下這一個方法:

public List<CGeoPoint> GetItin(CGeoPair latlongpair) 
    { 
     string RequestText = CreateRequest(latlongpair.GeoPoint1, latlongpair.GeoPoint2); 

     XmlDocument locationsResponse = MakeRequest(RequestText); 
     //Create namespace manager 
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(locationsResponse.NameTable); 
     nsmgr.AddNamespace("rest", "http://schemas.microsoft.com/search/local/ws/rest/v1"); 

     //Ovde kupim sve Itinerere čak i početnu i krajnju tačku. to se kasnije izbacuje 
     XmlNodeList locationElements = locationsResponse.SelectNodes("//rest:ItineraryItem", nsmgr); 

     List<CGeoPoint> itin = new List<CGeoPoint>(); 
     foreach (XmlNode location in locationElements) 
     { 
      decimal lat = decimal.Parse(location.SelectSingleNode(".//rest:Latitude", nsmgr).InnerText); 
      decimal longit = decimal.Parse(location.SelectSingleNode(".//rest:Longitude", nsmgr).InnerText); 
      string mantype = location.SelectSingleNode(".//rest:ManeuverType", nsmgr).InnerText; 
      mantype = mantype.ToUpper(); 

      if (mantype == "KEEPSTRAIGHT" || mantype == "CONTINUEROUTE") 
      { 
       //Do nothing... jump over 
      } 
      else 
      { 
       CGeoPoint ll = new CGeoPoint(lat, longit); 
       itin.Add(ll); 
      } 
     } 
     return itin; 
    }