从 Bing 地图解析 XML 考虑操作类型
本文关键字:操作 类型 XML Bing 地图 | 更新日期: 2023-09-27 18:37:05
我有一个代码,可以从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;
}
此代码返回了每个行程项的纬度和经度
好的
,我用以下方法解决了这个问题:
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;
}