示例#1
0
        public IList<LocationInfo> GetGeocodingList(string xml)
        {
            XmlDocument aXmlDocument = new XmlDocument();
            aXmlDocument.LoadXml(xml);

            XmlNodeList aDataInfoXmlNodeList = aXmlDocument.GetElementsByTagName(LocationInfo.DataInfoElementName);
            MapSearchResult aSearchResult = new MapSearchResult();

            if (aDataInfoXmlNodeList == null || aDataInfoXmlNodeList.Count == 0)
            {
                return null;
            }

            IList<LocationInfo> ltLocationInfo = new List<LocationInfo>();

            string province = string.Empty;
            string city = string.Empty;
            string dist = string.Empty;
            string area = string.Empty;
            string road = string.Empty;
            string point = string.Empty;
            string poiDirection = string.Empty;
            string poiDistance = string.Empty;
            string roadDirection = string.Empty;
            string roadDistance = string.Empty;
            string roadLevel = string.Empty;

            foreach (XmlNode anItemNode in aDataInfoXmlNodeList)
            {
                foreach (XmlNode anChildNode in anItemNode.ChildNodes)
                {
                    switch (anChildNode.Name)
                    {
                        case LocationInfo.ChildElementName.Province: province = anChildNode.InnerText; break;
                        case LocationInfo.ChildElementName.City: city = anChildNode.InnerText; break;
                        case LocationInfo.ChildElementName.Dist: dist = anChildNode.InnerText; break;
                        case LocationInfo.ChildElementName.Area: area = anChildNode.InnerText; break;
                        case LocationInfo.ChildElementName.Road:
                            {
                                road = anChildNode.ChildNodes[0].InnerText;
                                roadDirection = anChildNode.ChildNodes[1].InnerText;
                                roadDistance = anChildNode.ChildNodes[2].InnerText;
                                roadLevel = anChildNode.ChildNodes[3].InnerText;
                                break;
                            }
                        case LocationInfo.ChildElementName.Poi: point = anChildNode.InnerText; break;
                        case LocationInfo.ChildElementName.PoiDirection: poiDirection = anChildNode.InnerText; break;
                        case LocationInfo.ChildElementName.PoiDistance: poiDistance = anChildNode.InnerText; break;
                    }
                }

                ltLocationInfo.Add(new LocationInfo(province, city, dist, area, point, poiDirection, poiDistance,road, roadDirection, roadDistance, roadLevel));
            }

            return ltLocationInfo;
        }
示例#2
0
        public MapSearchResult GetMapSearchResult(string xml)
        {
            XmlDocument aXmlDocument = new XmlDocument();
            aXmlDocument.LoadXml(xml);

            XmlNodeList aDataInfoXmlNodeList = aXmlDocument.GetElementsByTagName(MapSearchResult.DataInfoElementName);
            MapSearchResult aSearchResult = new MapSearchResult();

            if (aDataInfoXmlNodeList == null || aDataInfoXmlNodeList.Count == 0)
            {
                return null;
            }
            XmlNode aDataNode = aDataInfoXmlNodeList[0];
            aSearchResult.AllResultCount = Convert.ToInt32(aDataNode.Attributes[MapSearchResult.DataInfoAttributeName_AllCount].Value);
            aSearchResult.PageNum = Convert.ToInt32(aDataNode.Attributes[MapSearchResult.DataInfoAttributeName_PageNum].Value);
            aSearchResult.CurrentResultCount = Convert.ToInt32(aDataNode.Attributes[MapSearchResult.DataInfoAttributeName_CurrentCount
                ].Value);

            List<MapSearchResultItem> ltResultItem = new List<MapSearchResultItem>();
            string strLatLon = string.Empty;
            string name = string.Empty;
            string highName = string.Empty;
            string address = string.Empty;
            string phone = string.Empty;
            string type = string.Empty;

            foreach (XmlNode anItemNode in aDataNode.ChildNodes)
            {
                foreach (XmlNode anChildNode in anItemNode.ChildNodes)
                {
                    switch (anChildNode.Name)
                    {
                        case MapSearchResultItem.ChildElementName.StrLatLon: strLatLon = anChildNode.InnerText; break;
                        case MapSearchResultItem.ChildElementName.Name: name = anChildNode.InnerText; break;
                        case MapSearchResultItem.ChildElementName.HighName: highName = anChildNode.InnerText; break;
                        case MapSearchResultItem.ChildElementName.Type: type = anChildNode.InnerText; break;
                        case MapSearchResultItem.ChildElementName.Address: address = anChildNode.InnerText; break;
                        case MapSearchResultItem.ChildElementName.Phone: phone = anChildNode.InnerText; break;
                    }
                }

                ltResultItem.Add(new MapSearchResultItem(strLatLon, name, highName, address, phone, type));
            }

            if (ltResultItem.Count == 0)
            {
                return null;
            }

            aSearchResult.Items = ltResultItem;
            return aSearchResult;
        }