/// <summary> /// /// </summary> /// <param name="url"></param> /// <returns></returns> public List <POIInfo> GetPoiInfos(string url) { List <POIInfo> poiList = new List <POIInfo>(); HttpWebResponse hwr = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string context = HttpHelper.GetResponseString(hwr); context = context.Substring(22, context.Length - 24); object t = JsonHelper.JsonDeserialize <object>(context); Dictionary <string, object> dicT = t as Dictionary <string, object>; Dictionary <string, object> dicInfos = (dicT["content"] as object[])[0] as Dictionary <string, object>; object[] infos = dicInfos["uids"] as object[]; if (infos.Length == 0) { return(poiList); } foreach (object i in infos.ToList()) { Dictionary <string, object> icon = (i as Dictionary <string, object>)["icon"] as Dictionary <string, object>; object x = icon["x"]; object y = icon["y"]; object ty = (i as Dictionary <string, object>)["type"]; object name = (i as Dictionary <string, object>)["name"]; object uid = (i as Dictionary <string, object>)["uid"]; double doubleX = double.Parse(x.ToString()); double doubleY = double.Parse(y.ToString()); string id = uid.ToString(); POIInfo poiInfo = new POIInfo(); poiInfo.name = name.ToString(); poiInfo.type = ty.ToString(); poiInfo.x = doubleX; poiInfo.y = doubleY; Coord c = CoordHelper.BdDecrypt(poiInfo.y, poiInfo.x); c = CoordHelper.Gcj2Wgs(c.lon, c.lat); poiInfo.cx = c.lon; poiInfo.cy = c.lat; if (this.dicIDs.ContainsKey(id)) { continue; } else { POIDeInfo poiDeInfo = this.GetDetailInfo(id); Coord coord = this.coordProjection(doubleX, doubleY); if (coord != null) { poiInfo.x = coord.lon; poiInfo.y = coord.lat; } if (poiDeInfo != null) { poiInfo.phone = poiDeInfo.phone; poiInfo.type = poiDeInfo.type; poiInfo.address = poiDeInfo.address; } } poiList.Add(poiInfo); } return(poiList); }
private POIDeInfo getDetailInfoKeyWord(string id) { POIDeInfo poiDetailInfo = new POIDeInfo(); poiDetailInfo.id = id; string url = "http://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&pcevaname=pc2&da_par=baidu&from=webmap&qt=inf&uid=" + id + "&ie=utf-8"; HttpWebResponse hwr = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string context = HttpHelper.GetResponseString(hwr); object t = JsonHelper.JsonDeserialize <object>(context); Dictionary <string, object> detail = t as Dictionary <string, object>; if (detail == null || (detail as Dictionary <string, object>)["content"] == null) { return(poiDetailInfo); } Dictionary <string, object> dicContext = (detail as Dictionary <string, object>)["content"] as Dictionary <string, object>; if (dicContext.ContainsKey("addr") && dicContext["addr"] != null) { poiDetailInfo.address = dicContext["addr"].ToString(); } if (dicContext.ContainsKey("tag") && dicContext["tag"] != null) { poiDetailInfo.type = dicContext["tag"].ToString(); } if (dicContext.ContainsKey("tel") && dicContext["tel"] != null) { poiDetailInfo.phone = dicContext["tel"].ToString(); } return(poiDetailInfo); }
/// <summary> /// 根据关键字获取兴趣点信息 /// </summary> /// <param name="minRow">最小行号</param> /// <param name="maxRow">最大行号</param> /// <param name="minCol">最小列号</param> /// <param name="maxCol">最大列号</param> ///<param name="zoom">地图层级</param> /// <param name="keyWord">关键字</param> /// <returns>兴趣点列表</returns> public List <POIInfo> GetPoiInfos(int minRow, int maxRow, int minCol, int maxCol, int zoom, string keyWord) { List <POIInfo> poiInfoList = new List <POIInfo>(); for (int i = minRow; i < maxRow; i++) { for (int j = minCol; j < maxCol; j++) { try { string url = "http://mt0.google.cn/vt?pb="; string n = "!1m4!1m3!1i" + zoom.ToString() + "!2i" + i.ToString() + "!3i" + j.ToString(); url += n; url += "!2m3!1e0!2sm!3i!3m9!2szh-CN!3sCN!5e18!12m1!1e50!12m3!1e37!2m1!1ssmartmaps!4e3&callback"; Cookie ck = new Cookie("NID", "67=NFg3Uhf4DA2v8o5ocSGVOL-aRgTgIQuu60KMagzDXXio5NfyWfZ1GdnCiOD0oiMZ5KNcgLjw80g_lIRN7qduKn8DaObXjWUI6T_ikmqcBVkqYPaXHyefhb1leb1c4oEI", "/", "mt0.google.cn"); Cookie ck2 = new Cookie("PREF", "ID=49a50c62c452e4b2:U=8fb8ca3a2befd2dd:NW=1:TM=1419327444:LM=1419327658:S=sFI0jDHVntczyAsT", "/", "mt0.google.cn"); CookieCollection coll = new CookieCollection(); coll.Add(ck); coll.Add(ck2); HttpWebResponse coordshr = HttpHelper.CreateGetHttpResponse(url, 5000, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", coll); string cf = HttpHelper.GetResponseString(coordshr); object fObj = JsonHelper.JsonDeserialize <object>(cf); foreach (object b in (fObj as Array)) { Dictionary <string, object> dic = b as Dictionary <string, object>; object o = dic["features"]; foreach (object xo in (o as Array)) { Dictionary <string, object> dxo = xo as Dictionary <string, object>; POIInfo poiInfo = new POIInfo(); string id = dxo["id"].ToString(); object nobj = JsonHelper.JsonDeserialize <object>(dxo["c"].ToString()); Dictionary <string, object> dicname = nobj as Dictionary <string, object>; Dictionary <string, object> dicName2 = dicname["1"] as Dictionary <string, object>; poiInfo.name = dicName2["title"].ToString(); POIDeInfo pDeinfo = this.getDetailInfo(id); if (pDeinfo.type.Contains(keyWord) || poiInfo.name.Contains(keyWord)) { poiInfo.x = pDeinfo.x; poiInfo.y = pDeinfo.y; poiInfo.type = pDeinfo.type; poiInfo.phone = pDeinfo.phone; poiInfo.address = pDeinfo.address; poiInfoList.Add(poiInfo); if (this.SaveDataEvent != null && poiInfoList.Count % this.saveStep == 0) { this.SaveDataEvent(poiInfoList); } } } } } catch { } } } return(poiInfoList); }
/// <summary> /// 根据地址查询兴趣点信息 /// </summary> /// <param name="url">地址</param> /// <returns>兴趣点信息</returns> private void GetPoiInfos(string url) { try { HttpWebResponse hwr = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", GetCookies()); string context = HttpHelper.GetResponseString(hwr); object t = JsonHelper.JsonDeserialize <object>(context); object[] xs = t as object[]; for (int i = 0; i < xs.Length; i++) { object ps = xs[i]; object[] pps = ps as object[]; object[] objects = pps[4] as object[]; for (int j = 0; j < objects.Length; j++) { object[] oos = objects[j] as object[]; object[] xos = oos[0] as object[]; for (int k = 0; k < xos.Length; k++) { object[] obs = xos[k] as object[]; string name = (obs.Length > 0 && obs[0] != null) ? obs[0].ToString() : ""; string id = (obs.Length > 0 && obs[obs.Length - 1] != null) ? obs[obs.Length - 1].ToString() : ""; if (id != "") { POIInfo poiInfo = new POIInfo(); POIDeInfo poiDeInfo = this.getDetailInfo(id); if (poiDeInfo == null || poiDeInfo.name == "") { continue; } poiInfo.name = poiDeInfo.name; poiInfo.address = poiDeInfo.address.Replace(",", ""); //poiInfo.address.Replace(",", ""); poiInfo.type = poiDeInfo.type; poiInfo.phone = poiDeInfo.phone; poiInfo.x = poiDeInfo.x; poiInfo.y = poiDeInfo.y; Coord c = CoordHelper.Gcj2Wgs(poiInfo.x, poiInfo.y); poiInfo.cx = c.lon; poiInfo.cy = c.lat; poiInfo.pName = poiDeInfo.pName; poiInfo.cName = poiDeInfo.cName; poiInfo.dName = poiDeInfo.dName; poiInfo.roadName = poiDeInfo.roadName; this.POICount++; if (this.DowningEvent != null) { this.DowningEvent(poiInfo, this.index, this.count); } } } } } } catch { } }
/// <summary> /// 根据地址获取兴趣点信息(关键字查询) /// </summary> /// <param name="url">地址</param> /// <returns></returns> private void getPoiInfosKeyWord(string url) { try { HttpWebResponse hwr = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", GetCookies()); string context = HttpHelper.GetResponseString(hwr); object t = JsonHelper.JsonDeserialize <object>(context); Dictionary <string, object> ts = t as Dictionary <string, object>; if (ts.ContainsKey("tiles")) { object[] objs = ts["tiles"] as object[]; Dictionary <string, object> ob = objs[0] as Dictionary <string, object>; object[] osx = ob["tile"] as object[]; for (int i = 0; i < osx.Length; i++) { POIInfo poiInfo = new POIInfo(); Dictionary <string, object> dicox = osx[i] as Dictionary <string, object>; string id = dicox["id"].ToString(); poiInfo.name = dicox["name"].ToString(); POIDeInfo poiDeInfo = this.getDetailInfo(id); if (poiDeInfo != null && poiDeInfo.name != "") { poiInfo.name = poiDeInfo.name; poiInfo.address = poiDeInfo.address; poiInfo.type = poiDeInfo.type; poiInfo.phone = poiDeInfo.phone; poiInfo.x = poiDeInfo.x; poiInfo.y = poiDeInfo.y; Coord c = CoordHelper.Gcj2Wgs(poiInfo.x, poiInfo.y); poiInfo.cx = c.lon; poiInfo.cy = c.lat; poiInfo.roadName = poiDeInfo.roadName; poiInfo.pName = poiDeInfo.pName; poiInfo.cName = poiDeInfo.cName; poiInfo.dName = poiDeInfo.dName; poiInfo.address.Replace(",", ""); this.POICount++; if (this.DowningEvent != null) { this.DowningEvent(poiInfo, this.index, this.count); } } } } } catch (Exception ex) { log.ErrorFormat("请求{0} 出错:{1}", url, ex); } }
private List <POIInfo> getKeywordPOI(string url) { List <POIInfo> poiList = new List <POIInfo>(); HttpWebResponse hwr = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string context = HttpHelper.GetResponseString(hwr); object t = JsonHelper.JsonDeserialize <object>(context); Dictionary <string, object> dicT = t as Dictionary <string, object>; object[] dicInfos = dicT["uids"] as object[]; for (int i = 0; i < dicInfos.Length; i++) { Dictionary <string, object> dic = dicInfos[i] as Dictionary <string, object>; POIInfo poiInfo = new POIInfo(); object objX = dic["x"]; object objY = dic["y"]; object objID = dic["uid"]; object objName = dic["name"]; if (objX != null && objY != null) { double.TryParse(objX.ToString(), out poiInfo.x); double.TryParse(objY.ToString(), out poiInfo.y); } if (objName != null) { poiInfo.name = objName.ToString(); } if (objID != null) { string id = objID.ToString(); POIDeInfo poiDetailInfo = this.getDetailInfoKeyWord(id); poiInfo.address = poiDetailInfo.address; poiInfo.phone = poiDetailInfo.phone; poiInfo.type = poiDetailInfo.type; } Coord coord = this.coordProjection(poiInfo.x, poiInfo.y); if (coord != null) { poiInfo.x = coord.lon; poiInfo.y = coord.lat; Coord c = CoordHelper.BdDecrypt(poiInfo.y, poiInfo.x); c = CoordHelper.Gcj2Wgs(c.lon, c.lat); poiInfo.cx = c.lon; poiInfo.cy = c.lat; } poiList.Add(poiInfo); } return(poiList); }
private POIDeInfo getDetailInfo2(string id) { POIDeInfo poiDetailInfo = new POIDeInfo(); poiDetailInfo.id = id; string url = "http://api.map.baidu.com/place/v2/detail?uid={0}&ak={1}&output=json"; Random rd = new Random(); int kindex = rd.Next(0, this.keys.Length); url = string.Format(url, id, this.keys[kindex]); HttpWebResponse hwr = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string context = HttpHelper.GetResponseString(hwr); object t = JsonHelper.JsonDeserialize <object>(context); Dictionary <string, object> detail = t as Dictionary <string, object>; if (detail == null || (detail as Dictionary <string, object>)["result"] == null) { return(poiDetailInfo); } Dictionary <string, object> dicContext = (detail as Dictionary <string, object>)["result"] as Dictionary <string, object>; if (dicContext.ContainsKey("name") && dicContext["name"] != null) { poiDetailInfo.name = dicContext["name"].ToString(); } if (dicContext.ContainsKey("location") && dicContext["location"] != null) { Dictionary <string, object> dicxy = dicContext["location"] as Dictionary <string, object>; string stringX = dicxy["lng"] != null ? dicxy["lng"].ToString() : ""; string stringY = dicxy["lat"] != null ? dicxy["lat"].ToString() : ""; double.TryParse(stringX, out poiDetailInfo.x); double.TryParse(stringY, out poiDetailInfo.y); } if (dicContext.ContainsKey("address") && dicContext["address"] != null) { poiDetailInfo.address = dicContext["address"].ToString(); } if (dicContext.ContainsKey("telephone") && dicContext["telephone"] != null) { poiDetailInfo.phone = dicContext["telephone"].ToString(); } return(poiDetailInfo); }
public POIDeInfo GetDetailInfo(string poiID) { POIDeInfo poiDetailInfo = new POIDeInfo(); ///根据id去请求相信信息, string tempUrl = "http://map.baidu.com/?qt=inf&uid=" + poiID + "&t=1428040686134"; try { HttpWebResponse ht = HttpHelper.CreateGetHttpResponse(tempUrl, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string ff = HttpHelper.GetResponseString(ht); object detail = JsonHelper.JsonDeserialize <object>(ff); string ty = ""; if (detail == null || (detail as Dictionary <string, object>)["content"] == null) { return(poiDetailInfo); } Dictionary <string, object> dicContext = (detail as Dictionary <string, object>)["content"] as Dictionary <string, object>; if (dicContext.ContainsKey("std_tag") && dicContext["std_tag"] != null) { object cla = dicContext["std_tag"]; ty = cla.ToString(); } string address = ""; if (dicContext.ContainsKey("addr") && dicContext["addr"] != null) { address = dicContext["addr"].ToString(); } string tel = ""; if (dicContext.ContainsKey("tel") && dicContext["tel"] != null) { tel = dicContext["tel"].ToString(); } string n = ""; Dictionary <string, object> dicResult = (detail as Dictionary <string, object>)["result"] as Dictionary <string, object>; if (dicResult != null && dicResult.ContainsKey("wd") && dicResult["wd"] != null) { n = dicResult["wd"].ToString(); } string city = ""; Dictionary <string, object> dicCity = (detail as Dictionary <string, object>)["current_city"] as Dictionary <string, object>; if (dicCity != null && dicCity["name"] != null) { city = dicCity["name"].ToString(); } string province = ""; if (dicCity != null && dicCity["up_province_name"] != null) { province = dicCity["up_province_name"].ToString(); } poiDetailInfo.address = address; poiDetailInfo.id = poiID; poiDetailInfo.phone = tel; poiDetailInfo.type = ty; } catch (Exception ex) { log.ErrorFormat("请求{0} 出错:{1}", tempUrl, ex); } return(poiDetailInfo); }
/// <summary> /// 根据id查询兴趣点详细信息 /// </summary> /// <param name="id">兴趣点id</param> /// <returns>兴趣点详细信息</returns> public POIDeInfo getDetailInfo(string id) { POIDeInfo dinfo = new POIDeInfo(); poiindex++; Random r = new Random(); int index = r.Next(0, this.keys.Length); string url = "http://restapi.amap.com/v3/place/detail?id=" + id + "&s=rsv3&key=" + this.keys[index]; try { HttpWebResponse ht = HttpHelper.CreateGetHttpResponse( url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string ff = HttpHelper.GetResponseString(ht); object detail = JsonHelper.JsonDeserialize <object>(ff); Dictionary <string, object> dicContext = detail as Dictionary <string, object>; if (!dicContext.ContainsKey("pois")) { return(dinfo); } object obj = dicContext["pois"]; if (obj != null) { object[] objs = obj as object[]; if (objs.Length > 0) { Dictionary <string, object> objects = objs[0] as Dictionary <string, object>; string name = objects["name"] != null ? objects["name"].ToString() : ""; string address = objects["address"] != null ? objects["address"].ToString() : ""; address = address == "System.Object[]" ? string.Empty : address; string tel = ""; if (objects["tel"] is Array) { object[] otels = objects["tel"] as object[]; for (int i = 0; i < otels.Length; i++) { if (tel != "") { tel = tel + ";" + otels[i] != null ? otels[i].ToString() : ""; } else { tel = otels[i] != null ? otels[i].ToString() : ""; } } } else { tel = objects["tel"] != null ? objects["tel"].ToString() : ""; } string xy = objects["location"] != null ? objects["location"].ToString() : ""; string str_longitude = xy.Split(',')[0]; //objects["longitude"] != null ? objects["longitude"].ToString() : ""; string str_latitude = xy.Split(',')[1]; //objects["latitude"] != null ? objects["latitude"].ToString() : ""; //string typecode = objects["typecode"] != null ? objects["typecode"].ToString() : ""; string typeString = objects["type"] != null ? objects["type"].ToString() : ""; dinfo.pName = objects["pname"] != null ? objects["pname"].ToString() : ""; dinfo.cName = objects["cityname"] != null ? objects["cityname"].ToString() : ""; dinfo.dName = objects["adname"] != null ? objects["adname"].ToString() : ""; dinfo.name = name; dinfo.address = address; dinfo.type = typeString; dinfo.phone = tel; double.TryParse(str_longitude, out dinfo.x); double.TryParse(str_latitude, out dinfo.y); } } } catch (Exception ex) { log.ErrorFormat("请求{0} 出错:{1}", url, ex); } return(dinfo); }
/// <summary> /// 根据id获取兴趣点详细信息 /// </summary> /// <param name="id">兴趣点唯一ID</param> /// <returns></returns> public POIDeInfo getDetailInfo(string id) { POIDeInfo dinfo = new POIDeInfo(); string url = "http://www.google.cn/maps/preview/entity?authuser=0&hl=zh-CN&pb=!1m14!1s0x0000000000000000%3A0x"; string temp = "!3m9!1m3!1d33333!2d0!3d0!2m0!3m2!1i1440!2i777!4f13.1!4m2!3d0!4d0!12m9!1e1!1e2!1e5!1e9!1e3!1e10!1e12!1e15!4smaps_sv.tactile!13m14!1e1!1e2!1e5!1e11!1e4!1e3!1e9!1e10!1e12!1e15!2m2!1i203!2i100!5smaps_sv.tactile!14m6!1s0!3b1!4m1!2i5210!7e81!12e9!22m1!1e810"; url = url + id + temp; Cookie ck = new Cookie("NID", "67=NFg3Uhf4DA2v8o5ocSGVOL-aRgTgIQuu60KMagzDXXio5NfyWfZ1GdnCiOD0oiMZ5KNcgLjw80g_lIRN7qduKn8DaObXjWUI6T_ikmqcBVkqYPaXHyefhb1leb1c4oEI", "/", "mt0.google.cn"); Cookie ck2 = new Cookie("PREF", "ID=49a50c62c452e4b2:U=8fb8ca3a2befd2dd:NW=1:TM=1419327444:LM=1419327658:S=sFI0jDHVntczyAsT", "/", "mt0.google.cn"); CookieCollection coll = new CookieCollection(); coll.Add(ck); coll.Add(ck2); HttpWebResponse coordshr = HttpHelper.CreateGetHttpResponse(url, 5000, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", coll); string cf = HttpHelper.GetResponseString(coordshr); cf = cf.Substring(5); object fObj = JsonHelper.JsonDeserialize <object>(cf); object x = fObj; object[] xs = fObj as object[]; object xs1 = xs[0]; object[] xs1s = xs1 as object[]; object xs2 = xs1s[1]; object[] xs2s = xs2 as object[]; object xs3 = xs2s[0]; object[] xs3s = xs3 as object[]; object xs4 = xs3s[14]; object[] xs4s = xs4 as object[]; object xs5 = xs4s[2]; object[] xs5s = xs5 as object[]; if (xs5s.Length > 0) { for (int i = 0; i < xs5s.Length; i++) { if (xs5s != null) { dinfo.address += xs5s[i].ToString(); } } } object xs10 = xs4s[3]; object[] xs10s = xs10 as object[]; if (xs10s != null && xs10s.Length > 0 && xs10s[0] != null) { dinfo.phone = xs10s[0].ToString(); } object xs6 = xs4s[9]; object[] xs6s = xs6 as object[]; if (xs6s[3] != null) { double.TryParse(xs6s[3].ToString(), out dinfo.x); } if (xs6s[2] != null) { double.TryParse(xs6s[2].ToString(), out dinfo.y); } object xs7 = xs4s[13]; object[] xs7s = xs7 as object[]; object xs8 = xs7s[0]; if (xs8 != null) { dinfo.type = xs8.ToString(); } return(dinfo); }