[英]Parsing XML from Bing Maps considering manouvertype
我有一個代碼可以從Bing Maps解析XML,並在其中解析行程點。 有趣的是,當我進行視覺展示時,我發現Bing的行為異常。 因此,有時它可以使我在沒有十字路口的直路上獲得積分。 這對我的應用程序來說是個問題,因為我獲得的積分超出了應有的水平。
問題 :我想消除標記: 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返回了緯度和經度
好的,我用以下方法解決了這個問題:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.