/// <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); }
/// <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 void DownPoIbyExtent(double x1, double y1, double x2, double y2, string keyWords, int index, int count) { for (int pindex = 0; pindex < 38; pindex++) { var keyWordsList = new List <string>(); if (keyWords == string.Empty) { keyWordsList.Add("美食$宾馆$购物$汽车$生活$结婚$丽人$金融$休闲娱乐$医疗"); keyWordsList.Add("旅游$教育$房地产$政府机构$公司企业$公交站$学校$小区"); } else { keyWordsList.Add(keyWords); } foreach (string keyword in keyWordsList) { Random rd = new Random(); int kindex = rd.Next(0, this.keys.Length); string url = string.Format( this.baiduPoiUrl, keyword, y1 + "," + x1 + "," + y2 + "," + x2, pindex, this.keys[kindex]); try { HttpWebResponse ht = HttpHelper.CreateGetHttpResponse( url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null); string ff = HttpHelper.GetResponseString(ht); var detail = JsonHelper.JsonDeserialize <object>(ff); var dicResult = detail as Dictionary <string, object>; if (dicResult.ContainsKey("status") && dicResult["status"].ToString() != "0") { log.ErrorFormat("{0}请求失败,返回码:{1}", url, dicResult["status"]); continue; } if (dicResult != null && dicResult.ContainsKey("results")) { object poiObjs = dicResult["results"]; var pois = poiObjs as object[]; if (pois.Length == 0) { if (this.DowningMessageEvent != null) { this.DowningMessageEvent(index, count); } break; } foreach (object poi in pois) { var poiInfo = new POIInfo(); this.poiCount++; var objects = poi as Dictionary <string, object>; if (objects.ContainsKey("name") && objects["name"] != null) { poiInfo.name = objects["name"].ToString(); } if (objects.ContainsKey("location") && objects["location"] != null) { var dicxy = objects["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 poiInfo.x); double.TryParse(stringY, out poiInfo.y); Coord c = CoordHelper.BdDecrypt(poiInfo.y, poiInfo.x); c = CoordHelper.Gcj2Wgs(c.lon, c.lat); poiInfo.cx = c.lon; poiInfo.cy = c.lat; } if (objects.ContainsKey("address") && objects["address"] != null) { poiInfo.address = objects["address"].ToString(); } if (objects.ContainsKey("telephone") && objects["telephone"] != null) { poiInfo.phone = objects["telephone"].ToString(); } if (this.DowningEvent != null) { this.DowningEvent(poiInfo, index, count); } } } else { log.WarnFormat("请求{0} 出错", url); } } catch (Exception ex) { log.ErrorFormat("请求{0} 出错:{1}", url, ex); } } if (this.DowningMessageEvent != null) { this.DowningMessageEvent(index, count); } } }
private void DownPoiInfobyExtent(double x1, double y1, double x2, double y2, string keyWord, int curentIndex, int count) { keyWord = !String.IsNullOrEmpty(keyWord) ? keyWord : "汽车|摩托|餐饮|购物|生活|体育|医疗|住宿|风景|住宅|政府|科教|交通|金融|公司|行政地名|自然地名|小区|学校"; for (int pindex = 1; pindex < 21; pindex++) { string tempUrl = string.Format( this.poiUrl, keyWord, pindex, string.Join("|", new[] { x1.ToString(), y1.ToString(), x2.ToString(), y2.ToString() })); 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); Dictionary <string, object> dicResult = detail as Dictionary <string, object>; //{errcode:30000,errmsg:"Denied",data:{host:"wangsu.traffitor.amap.com"}} if (dicResult != null && dicResult.ContainsKey("status") && dicResult.ContainsKey("status").ToString() != "1") { log.WarnFormat("请求{0}出现错误,详细:{1}", tempUrl, ff); continue; } if (dicResult != null && dicResult["status"] != null && dicResult["status"].ToString() == "1") { object poiObjs = dicResult["list"]; object[] pois = poiObjs as object[]; if (pois.Length == 0) { break; } else { for (int i = 0; i < pois.Length; i++) { POIInfo poiInfo = new POIInfo(); this.POICount++; Dictionary <string, object> objects = pois[i] as Dictionary <string, object>; poiInfo.name = objects["name"] != null ? objects["name"].ToString() : ""; if (objects["address"] is Array) { string address = ""; object[] addresses = objects["tel"] as object[]; for (int j = 0; j < addresses.Length; j++) { if (address != "") { address = address + ";" + addresses[j] != null ? addresses[j].ToString() : ""; } else { address = addresses[j] != null ? addresses[j].ToString() : ""; } } } else { poiInfo.address = objects["address"] != null ? objects["address"].ToString() : ""; } poiInfo.address.Replace(",", ""); string tel = ""; if (objects["tel"] is Array) { object[] otels = objects["tel"] as object[]; for (int j = 0; j < otels.Length; j++) { if (tel != "") { tel = tel + ";" + otels[j] != null ? otels[j].ToString() : ""; } else { tel = otels[j] != null ? otels[j].ToString() : ""; } } } else { tel = objects["tel"] != null ? objects["tel"].ToString() : ""; } poiInfo.type = objects["type"] != null ? objects["type"].ToString() : ""; poiInfo.phone = tel; string str_longitude = objects["longitude"].ToString(); string str_latitude = objects["latitude"].ToString(); double.TryParse(str_longitude, out poiInfo.x); double.TryParse(str_latitude, out poiInfo.y); Coord c = CoordHelper.Gcj2Wgs(poiInfo.x, poiInfo.y); poiInfo.cx = c.lon; poiInfo.cy = c.lat; if (objects.ContainsKey("templateData")) { var templateData = (Dictionary <string, object>)objects["templateData"]; if (templateData.ContainsKey("aoi")) { var aoi = ((Dictionary <string, object>)objects["templateData"])["aoi"].ToString(); var tempAois = aoi.Split('_').ToList().Select( m => CoordHelper.Gcj2Wgs( double.Parse(m.Split(',')[0]), double.Parse(m.Split(',')[1])).ToString()).ToArray(); poiInfo.aoi = string.Join("_", tempAois); } } if (this.DowningEvent != null) { this.DowningEvent(poiInfo, curentIndex, count); } if (this.DowningMessageEvent != null) { this.DowningMessageEvent(curentIndex, count); } } } } } catch (Exception ex) { log.ErrorFormat("请求{0} 出错:{1}", url, ex); Console.WriteLine(ex.Message); } System.Threading.Thread.Sleep(500); } }