0

我有一个从 Bing 地图返回 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 返回了纬度和经度

4

1 回答 1

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;
    }  
于 2013-10-27T20:32:46.273 回答