示例#1
0
        /// <summary>
        /// 地方搜索
        /// </summary>
        /// <param name="userData">用户信息</param>
        /// <returns>返回信息</returns>
        private Hashtable[] funPlaceSearch(Hashtable userData)
        {
            moyu.Http myHttp = new Http();
            string url = "http://api.map.baidu.com/place/search";
            string parm = "?&query=" + userData["@body"].ToString().Substring(2);
            parm += "&key=d4597e2a57145c17dad7dc8ec4e20d58";
            parm += "&location=35.586056,104.626638&radius=10000";
            parm += "&output=xml";
            StreamReader reader = new StreamReader(myHttp.HttpGetAsStreamReader(url, parm).BaseStream);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(reader);
            ArrayList myList = new ArrayList();

            XmlNode statusNode = xmlDoc.SelectSingleNode("/PlaceSearchResponse/status");
            if (statusNode.InnerText == "OK")
            {
                XmlNode results = xmlDoc.SelectSingleNode("/PlaceSearchResponse/results");
                foreach (XmlNode result in results)
                {
                    Hashtable theResult = new Hashtable();
                    foreach (XmlNode attr in result)
                    {
                        theResult[attr.Name] = attr.InnerText;
                        if (attr.Name == "location")
                        {
                            foreach (XmlNode pos in attr)
                            {
                                theResult[pos.Name] = pos.InnerText;
                            }
                        }
                    }
                    myList.Add(theResult);
                }
            }
            int count = myList.Count > 9 ? 9 : myList.Count;
            Hashtable[] rtItems = new Hashtable[count];
            for (var i = 0; i < count; i++)
            {
                Hashtable nowItem = (Hashtable)myList[i];
                rtItems[i] = new Hashtable();
                rtItems[i]["id"] = 0;
                rtItems[i]["messageType"] = 1;
                rtItems[i]["title"] = nowItem["name"].ToString() + "\n" + nowItem["address"];
                if (nowItem.ContainsKey("telephone"))
                {
                    rtItems[i]["title"] = rtItems[i]["title"].ToString() + "," + nowItem["telephone"].ToString();
                }
                rtItems[i]["body"] = nowItem["name"].ToString() +
                    "\n" + nowItem["address"].ToString();
                if (nowItem.ContainsKey("telephone"))
                {
                    rtItems[i]["body"] = rtItems[i]["body"].ToString() + "\n" + nowItem["telephone"].ToString();
                }
                rtItems[i]["picSmall"] =getPicUrl(false) ;
                rtItems[i]["picBig"] = getPicUrl(true);
                rtItems[i]["url"] = "http://www.ai0932.com/mobile/placeSearch.aspx?name=" + nowItem["name"]+
                    "&address=" + nowItem["address"] + "&lat=" + nowItem["lat"] + "&lng=" + nowItem["lng"]+
                    (nowItem.ContainsKey("telephone") ? ("&tel=" + nowItem["telephone"]) : "");
                rtItems[i]["orders"] = i;
            }
            return rtItems;
        }