为微信公众平台加入搜索周围地方的功能
2013-09-07 10:25
113 查看
利用百度地图API,根据用户发送的位置,检测周围有什么,例如:餐厅,商场,便利店等等
获得的方法
private void ResponseMsg(string weixinXML) { string key=string.Empty; try { XmlDocument doc = new XmlDocument(); doc.LoadXml(weixinXML); string msgType = dx.MsgType; if (msgType.Equals("location")) { //处理位置消息 LocationType lt = dx.NewLocationType(dx.Xn); Response.Write(Utils.GetYourNear(lt.Location_Y, lt.Location_X, "餐厅", lt.FromUserName, lt.ToUserName)); } }
获得的方法
public static string GetYourNear(string location_X, string location_Y,string what, string UserOpenId, string DevOpenId) { string url = "http://api.map.baidu.com/telematics/v3/local?location=" + location_X + "," + location_Y + "&keyWord=" + HttpContext.Current.Server.UrlEncode(what) + "&output=xml&ak=" + BaiduKey; WebRequest webRequest = WebRequest.Create(url); HttpWebRequest request = webRequest as HttpWebRequest; request.Method = "GET"; request.ContentType = "application/json; charset=utf-8"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20100101 Firefox/20.0"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string tianqiXML = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(tianqiXML); XmlNode parentNode = xmlDoc.DocumentElement; if (parentNode["total"].InnerText == "0") { return ResponseWeixin.ResponseText("您好,您的周围不存在【" + what + "】!\n您可重新尝试!", UserOpenId, DevOpenId); } XmlNode aaa = parentNode["poiList"]; // XmlNode rList = aaa["poiList"]; List<news> items = new List<news>(); int i=1; foreach (XmlNode xn in aaa) { news item = new news(); item.Title = xn["name"].InnerText + " 电话:" + xn["telephone"].InnerText + " 距离:" + xn["distance"].InnerText + "米"; XmlNode bbb = xn["location"]; if(i==1) { item.PicUrl = "http://api.map.baidu.com/staticimage?center=" + bbb["lng"].InnerText + "," + bbb["lat"].InnerText + "&width=320&height=160&zoom=18&markers=" + bbb["lng"].InnerText + "," + bbb["lat"].InnerText + "&markerStyles=l,A"; }else { item.PicUrl = "http://api.map.baidu.com/staticimage?center=" + bbb["lng"].InnerText + "," + bbb["lat"].InnerText + "&width=80&height=80&zoom=15&markers=" + bbb["lng"].InnerText + "," + bbb["lat"].InnerText + "&markerStyles=l,A"; } i++; // item.PicUrl = ResponseWeixin.GetWebUrl() + "/weixin/png/logo.png"; items.Add(item); } return ResponseWeixin.ResponseSubscribe(items, UserOpenId, DevOpenId); }
相关文章推荐
- 如何给列表加入搜索功能
- Ajax.net --想在application中的某些地方加入ajax的功能,还是用ajax.net吧
- 自定义带有删除功能的edittext实例,在登录,搜索等地方经常用到可以直接用
- 谷歌在搜索中加入求职功能 有合适工作还会弹通知
- 有道词典的划词搜索功能加入生成的百度链接
- 给gridview加入查找(搜索)功能
- Google电影播放时间搜索 加入Google Maps功能
- 关于在CSDN Blog公告栏加入Google搜索功能的问题
- 给gridview加入查找(搜索)功能
- 关于在CSDN Blog公告栏加入Google搜索功能的问题
- 自带删除功能的输入框——在登录,搜索等地方经常用到可以直接用
- 如何给列表加入搜索功能
- 自定义带有删除功能的edittext实例,在登录,搜索等地方经常用到可以直接用
- 如何将网站的搜索功能加入到浏览器的搜索框 (IE7/FF2)
- 【IT动态】Google 移动搜索加入搜索应用程序功能,实用
- 网站加入Google搜索功能 嵌入Google搜索
- 在WordPress中加入Google搜索功能的简单步骤讲解
- 在WordPress中加入Google搜索功能的简单步骤讲解
- 在SQL Server 2005中用存储过程实现搜索功能
- win10 build9888版新发现:设置页整合搜索功能