[英]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.