public void Geohash_To_Point3() { string hash = "9v"; Point point = Geohash.ToPoint(hash); int stop = 0; }
private void OnValidate(object sender, EventArgs e) { try { double lat, lon, d, m, s; DMS.Flag ind; int len; string tmp; DMS.Decode("34d22\'34.567\"", out ind); DMS.Decode(-86.0, 32.0, 34.214); DMS.DecodeAngle("-67.4532"); DMS.DecodeAzimuth("85.3245W"); DMS.DecodeLatLon("86d34\'24.5621\"", "21d56\'32.1234\"", out lat, out lon, false); DMS.Encode(-86.453214, out d, out m); DMS.Encode(-86.453214, out d, out m, out s); DMS.Encode(-86.453214, DMS.Component.SECOND, 12, DMS.Flag.LONGITUDE, 0); DMS.Encode(-86.453214, 12, DMS.Flag.LONGITUDE, 0); Geohash.DecimalPrecision(12); Geohash.Forward(31.23456, -86.43678, 12, out tmp); Geohash.GeohashLength(0.001); Geohash.GeohashLength(0.002, 0.003); Geohash.LatitudeResolution(12); Geohash.LongitudeResolution(12); Geohash.Reverse("djds54mrfc0g", out lat, out lon, out len, true); GARS.Forward(32.0, -86.0, 2, out tmp); GARS.Reverse("189LE37", out lat, out lon, out len, true); Georef.Forward(32.0, -86.0, 2, out tmp); Georef.Reverse("GJEC0000", out lat, out lon, out len, true); MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnConvert(object sender, EventArgs e) { try { double lon = Double.Parse(m_LongitudeTextBox.Text); double lat = Double.Parse(m_latitudeTextBox.Text); m_longitudeDMSTextBox.Text = DMS.Encode(lon, 5, DMS.Flag.LONGITUDE, 0); m_latitudeDMSTextBox.Text = DMS.Encode(lat, 5, DMS.Flag.LATITUDE, 0); string tmp = ""; switch (m_comboBox.SelectedIndex) { case 0: // Geohash Geohash.Forward(lat, lon, 12, out tmp); break; case 1: // GARS GARS.Forward(lat, lon, 2, out tmp); break; case 2: // Georef Georef.Forward(lat, lon, 2, out tmp); break; } m_geohashTextBox.Text = tmp; } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnConvertGeohash(object sender, EventArgs e) { try { double lat = 0.0, lon = 0.0; int len; switch (m_comboBox.SelectedIndex) { case 0: // Geohash Geohash.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); break; case 1: // GARS GARS.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); break; case 2: // Georef Georef.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); break; } m_LongitudeTextBox.Text = lon.ToString(); m_latitudeTextBox.Text = lat.ToString(); m_longitudeDMSTextBox.Text = DMS.Encode(lon, 5, DMS.Flag.LONGITUDE, 0); m_latitudeDMSTextBox.Text = DMS.Encode(lat, 5, DMS.Flag.LATITUDE, 0); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { try { { // Sample forward calculation double lat = 57.64911, lon = 10.40744; // Jutland (the wikipedia example) string geohash; int maxlen = Geohash.GeohashLength(1.0e-5); for (int len = 0; len <= maxlen; ++len) { Geohash.Forward(lat, lon, len, out geohash); Console.WriteLine(geohash); } } { // Sample reverse calculation string geohash = "u4pruydqqvj"; double lat, lon; for (int i = 0; i <= geohash.Length; ++i) { int len; Geohash.Reverse(geohash.Substring(0, i), out lat, out lon, out len, true); Console.WriteLine(String.Format("Length: {0} Latitude: {1} Longitude: {2}", len, lat, lon)); } } } catch (GeographicErr e) { Console.WriteLine(String.Format("Caught exception: {0}", e.Message)); } }
public APIResult GetPagedList([FromBody] GetPagedListArgsModel args) { args.OrderName = args.OrderName ?? ""; if (args.PageSize <= 0) { args.PageSize = 10; } if (args.PageIndex == 0) { args.PageIndex = 1; } var query = db.Query <CommercialDistrict>() .Where(m => !m.IsDel); if (args.Latitude.HasValue && args.Longitude.HasValue) { //6 范围在±0.61KM if (!args.Precision.HasValue) { args.Precision = 6; } var geohash = Geohash.Encode(args.Latitude.Value, args.Longitude.Value, args.Precision.Value); var areas = GetGeoHashExpand(geohash); query = query.Where(m => m.GeoHash.StartsWith(areas[0]) || m.GeoHash.StartsWith(areas[1]) || m.GeoHash.StartsWith(areas[2]) || m.GeoHash.StartsWith(areas[3]) || m.GeoHash.StartsWith(areas[4]) || m.GeoHash.StartsWith(areas[5]) || m.GeoHash.StartsWith(areas[6]) || m.GeoHash.StartsWith(areas[7]) ); } var list = query .Select(m => new RowItem() { AddIp = m.AddIp, AddTime = m.AddTime, AddUser = m.AddUser, Flag = m.Flag, Id = m.Id, Address = m.Address, Detail = m.Detail, IsDel = m.IsDel, Latitude = m.Latitude, Longitude = m.Longitude, Name = m.Name }) .ToPagedList(args.PageIndex, args.PageSize); return(Success(new GetPagedListModel() { PageIndex = list.PageIndex, PageSize = list.PageSize, TotalCount = list.TotalItemCount, Items = list.ToList() })); }
public void Geohash_To_Point2() { string hash = "9ven09qv"; //31.99999809, -96.99983597 Point point = Geohash.ToPoint(hash); int stop = 0; }
public static SqlDouble[] DecodeGeohash(SqlString geohash) { ISpatialCoordinate coord = Geohash.DecodeGeoHash(geohash.ToString().ToCharArray()); SqlDouble[] coordinate = { new SqlDouble((double)coord.Latitude), new SqlDouble((double)coord.Longitude) }; return(coordinate); }
public void Geohash_To_Point() { string hash = "9vfg"; //haslet/keller/grapevine Point point = Geohash.ToPoint(hash); int stop = 0; }
/// <summary> /// lat = latutude /// lng = longitude /// IsActive = Flag to indicate if node is active [default=true]. /// </summary> public Node(double lat, double lng, bool IsActive = true) { LeftChild = null; RightChild = null; id = Geohash.Encode(lat, lng, precision); Lat = lat; Lng = lng; isActive = IsActive; }
public void UpdateInfo(Geoposition gp) { Info.Latitude = gp.Coordinate.Latitude.ToString("0.000000"); Info.Longitude = gp.Coordinate.Longitude.ToString("0.000000"); Info.LatitudeD = gp.Coordinate.Latitude; Info.LongitudeD = gp.Coordinate.Longitude; Info.GeoHash = Geohash.encode(Info.LatitudeD, Info.LongitudeD); Info.Accuracy = gp.Coordinate.Accuracy.ToString(CultureInfo.InvariantCulture); Info.Status = PositionStatus.Ready; Info.Ttl = DateTime.Now.Millisecond; AddOrUpdateCache(); }
public APIResult Update([FromBody] UpdateArgsModel args) { if (string.IsNullOrEmpty(args.Name)) { throw new ArgumentNullException("Name"); } if (string.IsNullOrEmpty(args.Flag)) { args.Flag = System.Guid.NewGuid().ToString(); } var model = db.Query <Shop>() .Where(m => m.Id == args.Id) .FirstOrDefault(); if (model == null) { throw new Exception("数据库记录不存在"); } var brand = db.GetSingle <ShopBrand>(args.ShopBrandId); if (brand == null) { throw new Exception("指定的商铺品牌不存在"); } model.ShopBrand = brand; model.Flag = args.Flag; model.Address = args.Address; model.AddressGuide = args.AddressGuide; model.Detail = args.Detail; model.Latitude = args.Latitude; model.Longitude = args.Longitude; model.Name = args.Name; model.OpenTime = args.OpenTime; model.ScoreValue = args.ScoreValue; model.Tel = args.Tel; model.UsePerUser = args.UsePerUser; model.Logo = args.Logo; model.IsShowApplets = args.IsShowApplets; model.Phone = args.Phone; if (model.Latitude.HasValue && model.Longitude.HasValue) { model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value); } else { model.GeoHash = string.Empty; } db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { if (string.IsNullOrEmpty(args.Name)) { throw new ArgumentNullException("Name"); } if (string.IsNullOrEmpty(args.Flag)) { args.Flag = System.Guid.NewGuid().ToString(); } var brand = db.GetSingle <ShopBrand>(args.ShopBrandId); if (brand == null) { throw new Exception("指定的商铺品牌不存在"); } var model = new Shop() { Flag = args.Flag, ShopBrand = brand, AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Address = args.Address, AddressGuide = args.AddressGuide, Detail = args.Detail, Latitude = args.Latitude, Longitude = args.Longitude, Name = args.Name, OpenTime = args.OpenTime, ScoreValue = args.ScoreValue, Tel = args.Tel, UsePerUser = args.UsePerUser, Logo = args.Logo, IsShowApplets = args.IsShowApplets }; if (model.Latitude.HasValue && model.Longitude.HasValue) { model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value); } else { model.GeoHash = string.Empty; } db.Add <Shop>(model); db.SaveChanges(); return(Success()); }
private void OnConvert(object sender, EventArgs e) { try { double lon = Double.Parse(m_LongitudeTextBox.Text); double lat = Double.Parse(m_latitudeTextBox.Text); m_longitudeDMSTextBox.Text = DMS.Encode(lon, 5, DMS.Flag.LONGITUDE, 0); m_latitudeDMSTextBox.Text = DMS.Encode(lat, 5, DMS.Flag.LATITUDE, 0); string tmp = ""; Geohash.Forward(lat, lon, 12, out tmp); m_geohashTextBox.Text = tmp; } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnConvertGeohash(object sender, EventArgs e) { try { double lat, lon; int len; Geohash.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); m_LongitudeTextBox.Text = lon.ToString(); m_latitudeTextBox.Text = lat.ToString(); m_longitudeDMSTextBox.Text = DMS.Encode(lon, 5, DMS.Flag.LONGITUDE, 0); m_latitudeDMSTextBox.Text = DMS.Encode(lat, 5, DMS.Flag.LATITUDE, 0); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnConvertDMS(object sender, EventArgs e) { try { DMS.Flag ind; double lon = DMS.Decode(m_longitudeDMSTextBox.Text, out ind); m_LongitudeTextBox.Text = lon.ToString(); double lat = DMS.Decode(m_latitudeDMSTextBox.Text, out ind); m_latitudeTextBox.Text = lat.ToString(); string tmp = ""; Geohash.Forward(lat, lon, 12, out tmp); m_geohashTextBox.Text = tmp; } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public APIResult Add([FromBody] AddArgsModel args) { if (string.IsNullOrEmpty(args.Name)) { throw new ArgumentNullException("Name"); } if (string.IsNullOrEmpty(args.Flag)) { args.Flag = System.Guid.NewGuid().ToString(); } if (!args.Status.HasValue) { args.Status = CommercialDistrictStatus.正常; } var model = new CommercialDistrict() { Flag = args.Flag, AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Address = args.Address, Name = args.Name, Status = args.Status.Value, Detail = args.Detail, Longitude = args.Longitude, Latitude = args.Latitude }; if (model.Latitude.HasValue && model.Longitude.HasValue) { model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value); } else { model.GeoHash = string.Empty; } db.Add <CommercialDistrict>(model); db.SaveChanges(); return(Success()); }
public APIResult Update([FromBody] UpdateArgsModel args) { if (string.IsNullOrEmpty(args.Name)) { throw new ArgumentNullException("Name"); } if (string.IsNullOrEmpty(args.Flag)) { args.Flag = System.Guid.NewGuid().ToString(); } if (!args.Status.HasValue) { args.Status = CommercialDistrictStatus.正常; } var model = db.Query <CommercialDistrict>() .Where(m => m.Id == args.Id) .FirstOrDefault(); if (model == null) { throw new Exception("数据库记录不存在"); } model.Flag = args.Flag; model.Name = args.Name; model.Status = args.Status.Value; model.Detail = args.Detail; model.Address = args.Address; model.Longitude = args.Longitude; model.Latitude = args.Latitude; if (model.Latitude.HasValue && model.Longitude.HasValue) { model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value); } else { model.GeoHash = string.Empty; } db.SaveChanges(); return(Success()); }
public void Geohash_Stress() { Random rand = new Random(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); List <string> hashes = new List <string>(); for (int i = 0; i < 100; i++) { double x = rand.Next(-179, 179); double y = rand.Next(-85, 85); string hash = Geohash.FromPoint(new Point(x, y), 6); //hashes[i] = hash; hashes.Add(hash); } sw.Stop(); long ms = sw.ElapsedMilliseconds; int stop = 0; }
private void update(HttpContext context, JObject httpObject) { #region HttpReSultMode resultMode = new HttpReSultMode(); TS_ClientUser Rmodel2 = JsonHelper.FromJson <TS_ClientUser>(httpObject["jsonEntity"].ToString()); var Loginmql = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.Id.Equal(Rmodel2.Id)); TS_ClientUser Loginmodel = OPBiz.GetEntity(Loginmql); Rmodel2.WhereExpression = TS_ClientUserSet.Id.Equal(Rmodel2.Id); Rmodel2.UpdateTime = DateTime.Now; Rmodel2.LocationUpdateTime = DateTime.Now; Rmodel2.isDeleted = Loginmodel.isDeleted;; Rmodel2.isValid = Loginmodel.isValid; Rmodel2.States = Loginmodel.States; if (Rmodel2.Longitude != null && Rmodel2.Latitude != null)//geohash编码 { double Latitude = double.Parse(Rmodel2.Latitude.ToString()); double Longitude = double.Parse(Rmodel2.Longitude.ToString()); Rmodel2.geohash = Geohash.Encode(Latitude, Longitude); } if (OPBiz.Update(Rmodel2) > 0) { resultMode.Code = 11; resultMode.Msg = "更新成功"; resultMode.Data = ""; } else { resultMode.Code = -13; resultMode.Msg = "更新失败"; resultMode.Data = ""; } #endregion context.Response.Write(JsonHelper.ToJson(resultMode, true)); context.Response.End(); }
/// <summary> /// 分类分页获取 /// </summary> /// <param name="context"></param> /// <param name="httpObject"></param> /// <param name="resultMode"></param> private void GetByCategory(HttpContext context, JObject httpObject, HttpReSultMode resultMode) { int pageIndex = 1; int pageSize = 10000; DataSet ds; #region if (httpObject["pageIndex"] != null) { pageIndex = int.Parse(httpObject["pageIndex"].ToString()); } if (httpObject["pageSize"] != null) { pageSize = int.Parse(httpObject["pageSize"].ToString()); } #region 条件 StringBuilder Where = new StringBuilder(); Where.Append(" isDeleted=0 and States>=0 "); if (httpObject["jsonEntity"]["KeyWords"] != null)//关键词 { string KeyWords = FilterTools.FilterSpecial(httpObject["jsonEntity"]["KeyWords"].ToString()); Where.Append(" and( Title like '%" + KeyWords + "%'"); Where.Append(" or Address like '%" + KeyWords + "%') "); } if (httpObject["jsonEntity"]["Category"] != null)//分类 { string Category = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Category"].ToString()); Where.Append(" and ( Category like '" + Category + "%')"); } if (httpObject["jsonEntity"]["MinPrice"] != null)//最低价 { string MinPrice = FilterTools.FilterSpecial(httpObject["jsonEntity"]["MinPrice"].ToString()); Where.Append(" and ( Price >" + MinPrice + ")"); } if (httpObject["jsonEntity"]["MaxPrice"] != null)//最高价 { string MaxPrice = FilterTools.FilterSpecial(httpObject["jsonEntity"]["MaxPrice"].ToString()); Where.Append(" and ( Price <" + MaxPrice + ")"); } if (httpObject["jsonEntity"]["ProvinceCode"] != null)//省 { string ProvinceCode = FilterTools.FilterSpecial(httpObject["jsonEntity"]["ProvinceCode"].ToString()); Where.Append(" and ( ProvinceCode like '" + ProvinceCode + "%')"); } if (httpObject["jsonEntity"]["CityCode"] != null)//城市 { string CityCode = FilterTools.FilterSpecial(httpObject["jsonEntity"]["CityCode"].ToString()); Where.Append(" and ( CityCode like '" + CityCode + "%')"); } if (httpObject["jsonEntity"]["AreaCode"] != null)//区 { string AreaCode = FilterTools.FilterSpecial(httpObject["jsonEntity"]["AreaCode"].ToString()); Where.Append(" and ( AreaCode like '" + AreaCode + "%')"); } #endregion #region 坐标 有距离 if (httpObject["jsonEntity"]["Longitude"] != null && httpObject["jsonEntity"]["Latitude"] != null)//传有坐标按距离排序 { string Longitude = httpObject["jsonEntity"]["Longitude"].ToString(); string Latitude = httpObject["jsonEntity"]["Latitude"].ToString(); string geohashWhere = Geohash.getsqlGeoHash(5, Latitude, Longitude, "geohash"); string sqlWhere = Where.ToString() + " and " + geohashWhere; //条件加geohash if (httpObject["jsonEntity"]["minKM"] != null && httpObject["jsonEntity"]["maxKM"] != null) //有最小最大距离约定,按距离排序, 不分页 { float minKM = float.Parse(httpObject["jsonEntity"]["minKM"].ToString()); float maxKM = float.Parse(httpObject["jsonEntity"]["maxKM"].ToString()); ds = OPBiz.GetByDistancesOrderByLL("v_TS_Transaction", sqlWhere, minKM, maxKM, Longitude, Latitude); } else //分页 按距离排序 { ds = OPBiz.GetPagingOrderByLL("v_TS_Transaction", sqlWhere, pageIndex, pageSize, Longitude, Latitude); } } else //简单分页无排序 { ds = OPBiz.GetPagingDataSet("v_TS_Transaction", Where.ToString(), pageIndex, pageSize, "CreateTime desc"); } #endregion if (ds != null && ds.Tables[0].Rows.Count > 0) { resultMode.Code = 11; resultMode.Msg = "获取成功"; resultMode.Data = JsonHelper.ToJson(ds.Tables[0], true); } else { resultMode.Code = 0; resultMode.Msg = "没有数据"; resultMode.Data = "[]"; } #endregion context.Response.Write(JsonHelper.ToJson(resultMode, true)); context.Response.End(); }
public override SetUserPosResponseBody ExecuteCore() { SetUserPosResponseBody res = new SetUserPosResponseBody(); //{ // "UserId": 1, // "UserPos": { // "Country": "中国", // "Province": "上海市", // "City": "上海市", // "District": "闵行区", // "Details": "上海市闵行区浦申路靠近上海闵行区金色阳光世博幼儿园", // "Latitude": 31.0732898712158, // "Longitude": 121.507202148438 // } //} using (HWLEntities db = new HWLEntities()) { //检测是否存在country province city district 没有就添加 t_country country = db.t_country.Where(c => c.name == this.request.Country).FirstOrDefault(); if (country == null) { country = new t_country() { id = 0, name = this.request.Country, }; db.t_country.Add(country); db.SaveChanges(); } t_province province = db.t_province.Where(p => p.name == this.request.Province).FirstOrDefault(); if (province == null) { province = new t_province() { id = 0, country_id = country.id, name = this.request.Province, }; db.t_province.Add(province); db.SaveChanges(); } t_city city = db.t_city.Where(c => c.name == this.request.City).FirstOrDefault(); if (city == null) { city = new t_city() { id = 0, province_id = province.id, name = this.request.City, }; db.t_city.Add(city); db.SaveChanges(); } t_district district = db.t_district.Where(p => p.name == this.request.District).FirstOrDefault(); if (district == null) { district = new t_district() { id = 0, city_id = city.id, name = this.request.District, }; db.t_district.Add(district); db.SaveChanges(); } //检测用户是否已经存在当前位置信息(条件,用户id,位置id,位置详情) t_user_pos upos = db.t_user_pos.Where(u => u.user_id == this.request.UserId && u.country_id == country.id && u.province_id == province.id && u.city_id == city.id && u.district_id == district.id && u.pos_details == this.request.Details ).FirstOrDefault(); if (upos == null) { //向用户位置表中加入数据 upos = new t_user_pos() { id = 0, create_date = DateTime.Now, update_date = DateTime.Now, geohash_key = Geohash.Encode(this.request.Latitude, this.request.Longitude), lat = this.request.Latitude, lon = this.request.Longitude, pos_details = this.request.Details, user_id = this.request.UserId, city_id = city.id, country_id = country.id, district_id = district.id, province_id = province.id, }; db.t_user_pos.Add(upos); } else { upos.update_date = DateTime.Now; } db.SaveChanges(); res.Status = ResultStatus.Success; res.UserPosId = upos.id; //保存用户的位置到redis Redis.UserAction userAction = new Redis.UserAction(); userAction.SavePos(upos.user_id, upos.lon, upos.lat); //获取当前位置附近的组 Redis.GroupAction groupAction = new Redis.GroupAction(); res.UserGroupGuid = groupAction.GetNearGroupGuid(upos.lon, upos.lat); if (string.IsNullOrEmpty(res.UserGroupGuid)) { //如果没有组数据,创建一个组 res.UserGroupGuid = groupAction.CreateNearGroupPos(upos.lon, upos.lat); //将用户加入到组中 groupAction.SaveGroupUser(res.UserGroupGuid, upos.user_id); } else { if (groupAction.ExistsInGroup(res.UserGroupGuid, upos.user_id)) { //如果用户当前所在位置与上次所在的位置不一样,则需要将用户从上次的群组里面移出来 if (!string.IsNullOrEmpty(this.request.LastGroupGuid) && this.request.LastGroupGuid != res.UserGroupGuid) { groupAction.DeleteGroupUser(this.request.LastGroupGuid, upos.user_id); } return(res); } else { //将用户加入到组中 groupAction.SaveGroupUser(res.UserGroupGuid, upos.user_id); } } //如果用户当前所在位置与上次所在的位置不一样,则需要将用户从上次的群组里面移出来 if (!string.IsNullOrEmpty(this.request.LastGroupGuid) && this.request.LastGroupGuid != res.UserGroupGuid) { groupAction.DeleteGroupUser(this.request.LastGroupGuid, upos.user_id); } //返回组用户列表 List <int> userIds = groupAction.GetGroupUserIds(res.UserGroupGuid); if (userIds == null || userIds.Count <= 0) { return(res); } res.GroupUserInfos = db.t_user.Where(u => userIds.Contains(u.id)) .Select(u => new UserSecretInfo() { UserId = u.id, UserName = u.name, UserImage = u.head_image, }).ToList(); } return(res); }
public JsonResult EditInfo(TS_ClientUser TS_ClientUserModle) { HttpReSultMode ReSultMode = new HttpReSultMode(); if (TS_ClientUserModle.Longitude != null && TS_ClientUserModle.Latitude != null)//geohash编码 { double Latitude = double.Parse(TS_ClientUserModle.Latitude.ToString()); double Longitude = double.Parse(TS_ClientUserModle.Longitude.ToString()); TS_ClientUserModle.geohash = Geohash.Encode(Latitude, Longitude); } bool IsAdd = false; if (TS_ClientUserModle.Details != null) { TS_ClientUserModle.Details = TS_ClientUserModle.Details.Replace("<", "<").Replace(">", ">"); } else { TS_ClientUserModle.Details = ""; } TS_ClientUserModle.UpdateTime = DateTime.Now; if (!(TS_ClientUserModle.Id != null && !TS_ClientUserModle.Id.ToString().Equals("00000000-0000-0000-0000-000000000000")))//id为空,是添加 { IsAdd = true; } if (IsAdd) { TS_ClientUserModle.Category = ""; TS_ClientUserModle.isDeleted = false; TS_ClientUserModle.isValid = 1; TS_ClientUserModle.Id = Guid.NewGuid(); TS_ClientUserModle.AddTime = DateTime.Now; TS_ClientUserModle.LocationUpdateTime = DateTime.Now; try { OPBiz.Add(TS_ClientUserModle); ReSultMode.Code = 11; ReSultMode.Data = TS_ClientUserModle.Id.ToString(); ReSultMode.Msg = "添加成功"; } catch (Exception e) { ReSultMode.Code = -11; ReSultMode.Data = e.ToString(); ReSultMode.Msg = "添加失败"; } } else { TS_ClientUserModle.WhereExpression = TS_ClientUserSet.Id.Equal(TS_ClientUserModle.Id); //TS_ClientUserModle.ChangedMap.Remove("doctorid");//移除主键值 if (OPBiz.Update(TS_ClientUserModle) > 0) { ReSultMode.Code = 11; ReSultMode.Data = ""; ReSultMode.Msg = "修改成功"; } else { ReSultMode.Code = -13; ReSultMode.Data = ""; ReSultMode.Msg = "修改失败"; } } return(Json(ReSultMode, JsonRequestBehavior.AllowGet)); }
public string GetData(HttpContext context) { HttpReSultMode resultMode = new HttpReSultMode(); try { int pageIndex = int.Parse(context.Request["Pageindex"]); int pageSize = int.Parse(context.Request["Pagesize"]); DataSet ds; #region 条件 StringBuilder Where = new StringBuilder(); Where.Append(" isDeleted=0 and States>0"); if (context.Request["keyWords"] != null)//关键词 { string KeyWords = FilterTools.FilterSpecial(context.Request["keyWords"].ToString()); Where.Append(" and( TName like '%" + KeyWords + "%'"); Where.Append(" or Address like '%" + KeyWords + "%' "); Where.Append(" or Details like '%" + KeyWords + "%') "); } if (context.Request["Category"] != null)//分类 { string Category = FilterTools.FilterSpecial(context.Request["Category"].ToString()); Where.Append(" and ( Category like '" + Category + "%')"); } #endregion #region 坐标 有距离 if (context.Request["Lng"] != null && context.Request["Lat"] != null)//传有坐标按距离排序 { string Longitude = context.Request["Lng"].ToString(); string Latitude = context.Request["Lat"].ToString(); //分页 按距离排序 string geohashWhere = Geohash.getsqlGeoHash(5, Latitude, Longitude, "geohash"); string sqlWhere = Where.ToString() + " and " + geohashWhere;//条件加geohash ds = OPBiz.GetPagingOrderByLL(sqlWhere, pageIndex, pageSize, Longitude, Latitude); } else //简单分页无排序 { ds = OPBiz.GetPagingDataSet(Where.ToString(), pageIndex, pageSize, "CreateTime desc"); } #endregion if (ds != null && ds.Tables[0].Rows.Count > 0) { resultMode.Code = 11; resultMode.Msg = "获取成功"; resultMode.Data = JsonHelper.ToJson(ds.Tables[0], true); } else { resultMode.Code = 0; resultMode.Msg = "没有数据"; resultMode.Data = "[]"; } } catch (Exception ex) { resultMode.Code = -11; resultMode.Data = ex.ToString(); } string result = JsonHelper.ToJson(resultMode, true); return(result); ; }
// 请求例子 /httpSever/TS_ClientUserHandler.ashx?json={"jsonEntity":{"UserName":"******","Pwd":"123456"},"action":"Login"} // 请求例子 /httpSever/TS_ClientUserHandler.ashx?json={"jsonEntity":{"UserName":"******","Pwd":"123456"},"action":"Register"} public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; // context.Response.Write("Hello World"); HttpReSultMode resultMode = new HttpReSultMode(); try { JObject httpObject = JsonHelper.FromJson(context.Request["json"]); // JObject ObjectParameter = (JObject)JsonConvert.DeserializeObject(httpObject["jsonEntity"].ObjToStr()); string jsonData = httpObject["jsonEntity"].ToString(); string UserName = ""; string Pwd = ""; switch (httpObject["action"].ToString()) { case "Register": UserName = FilterTools.FilterSpecial(httpObject["jsonEntity"]["UserName"].ToString()); var registermql = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.UserName.Equal(UserName)); TS_ClientUser registermodel = OPBiz.GetEntity(registermql); if (registermodel != null) { resultMode.Code = -13; resultMode.Msg = "用户已经存在"; resultMode.Data = ""; } else { TS_ClientUser Rmodel = JsonHelper.FromJson <TS_ClientUser>(jsonData); Rmodel.Id = Guid.NewGuid(); Rmodel.AddTime = DateTime.Now; Rmodel.UpdateTime = DateTime.Now; Rmodel.LocationUpdateTime = DateTime.Now; Rmodel.isDeleted = false; Rmodel.States = 0; if (Rmodel.Longitude != null && Rmodel.Latitude != null) //geohash编码 { double Latitude = double.Parse(Rmodel.Latitude.ToString()); double Longitude = double.Parse(Rmodel.Longitude.ToString()); Rmodel.geohash = Geohash.Encode(Latitude, Longitude); } OPBiz.Add(Rmodel); resultMode.Code = 11; resultMode.Msg = "注册成功"; resultMode.Data = Rmodel.Id.ToString(); } break; case "Login": UserName = FilterTools.FilterSpecial(httpObject["jsonEntity"]["UserName"].ToString()); Pwd = httpObject["jsonEntity"]["Pwd"].ToString(); var Loginmql = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.UserName.Equal(UserName).And(TS_ClientUserSet.Pwd.Equal(Pwd))); TS_ClientUser Loginmodel = OPBiz.GetEntity(Loginmql); if (Loginmodel != null) { resultMode.Code = 11; resultMode.Msg = "登录成功"; resultMode.Data = JsonHelper.ToJson(Loginmodel, true); } else { resultMode.Code = -13; resultMode.Msg = "用户或密码错误"; resultMode.Data = ""; } break; case "ChangePassword": UserName = FilterTools.FilterSpecial(httpObject["jsonEntity"]["UserName"].ToString()); Pwd = httpObject["jsonEntity"]["Pwd"].ToString(); var mqlG = TS_ClientUserSet.SelectAll().Where(TS_ClientUserSet.UserName.Equal(UserName)); TS_ClientUser modelG = OPBiz.GetEntity(mqlG); if (modelG != null) { modelG.Pwd = Pwd; modelG.UpdateTime = DateTime.Now; modelG.WhereExpression = TS_ClientUserSet.Id.Equal(modelG.Id); if (OPBiz.Update(modelG) > 0) { resultMode.Code = 11; resultMode.Msg = "修改密码成功"; resultMode.Data = ""; } else { resultMode.Code = -13; resultMode.Msg = "修改失败"; resultMode.Data = ""; } } else { resultMode.Code = -13; resultMode.Msg = "用户不存在"; resultMode.Data = ""; } break; case "update": this.update(context, httpObject); break; } } catch (Exception ex) { resultMode.Code = -1; resultMode.Data = ex.ToString(); } context.Response.Write(JsonHelper.ToJson(resultMode, true)); context.Response.End(); }
// 请求例子 /httpSever/TS_TransactionHandler.ashx?json={"jsonEntity":{"Category":"09","Longitude":"110.22587","Latitude":"25.272585"},"pageIndex":"1","pageSize":"20","action":"GetByCategory"} public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; // context.Response.Write("Hello World"); HttpReSultMode resultMode = new HttpReSultMode(); string Id = ""; int res = 0;//返回结果行数 try { JObject httpObject = JsonHelper.FromJson(context.Request["json"]); switch (httpObject["action"].ToString()) { case "GetById": #region Id = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString()); var mqlG = TS_TransactionSet.SelectAll().Where(TS_TransactionSet.Id.Equal(Id)); TS_Transaction modelG = OPBiz.GetEntity(mqlG); if (modelG != null) { resultMode.Code = 11; resultMode.Msg = "获取成功"; resultMode.Data = JsonHelper.ToJson(modelG, true); } else { resultMode.Code = -13; resultMode.Msg = "数据不存在"; resultMode.Data = ""; } #endregion break; case "GetByCategory": this.GetByCategory(context, httpObject, resultMode); break; case "add": #region TS_Transaction Rmodel = JsonHelper.FromJson <TS_Transaction>(httpObject["jsonEntity"].ToString()); Rmodel.Id = Guid.NewGuid(); Rmodel.CreateTime = DateTime.Now; Rmodel.CreateTime = DateTime.Now; Rmodel.isDeleted = false; Rmodel.isValid = 1; Rmodel.Clicks = 0; Rmodel.Praises = 0; Rmodel.CallCount = 0; Rmodel.States = 0; Rmodel.isTop = 0; if (Rmodel.Longitude != null && Rmodel.Latitude != null) //geohash编码 { double Latitude = double.Parse(Rmodel.Latitude.ToString()); double Longitude = double.Parse(Rmodel.Longitude.ToString()); Rmodel.geohash = Geohash.Encode(Latitude, Longitude); } OPBiz.Add(Rmodel); resultMode.Code = 11; resultMode.Msg = "添加成功"; resultMode.Data = Rmodel.Id.ToString(); #endregion break; case "update": #region TS_Transaction Rmodel2 = JsonHelper.FromJson <TS_Transaction>(httpObject["jsonEntity"].ToString()); var mqlu = TS_TransactionSet.SelectAll().Where(TS_TransactionSet.Id.Equal(Rmodel2.Id)); TS_Transaction modelu = OPBiz.GetEntity(mqlu); Rmodel2.CreateTime = modelu.CreateTime; Rmodel2.CreateTime = DateTime.Now; Rmodel2.isDeleted = modelu.isDeleted; Rmodel2.isValid = modelu.isValid; Rmodel2.Clicks = modelu.Clicks; Rmodel2.Praises = modelu.Praises; Rmodel2.CallCount = modelu.CallCount; Rmodel2.States = modelu.States; if (Rmodel2.Longitude != null && Rmodel2.Latitude != null) //geohash编码 { double Latitude = double.Parse(Rmodel2.Latitude.ToString()); double Longitude = double.Parse(Rmodel2.Longitude.ToString()); Rmodel2.geohash = Geohash.Encode(Latitude, Longitude); } Rmodel2.WhereExpression = TS_TransactionSet.Id.Equal(Rmodel2.Id); Rmodel2.UpdateTime = DateTime.Now; if (OPBiz.Update(Rmodel2) > 0) { resultMode.Code = 11; resultMode.Msg = "更新成功"; resultMode.Data = ""; } else { resultMode.Code = -13; resultMode.Msg = "更新失败"; resultMode.Data = ""; } #endregion break; case "ClickCount": //点击量 Id = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString()); res = OPBiz.SetCout("Id", Id, "Clicks"); if (res > 0) { resultMode.Code = 11; resultMode.Data = res.ToString(); resultMode.Msg = "统计成功"; } else { resultMode.Code = -13; resultMode.Data = "0"; resultMode.Msg = "统计失败!"; } break; case "PraiseCount": //点赞量加1 Id = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString()); res = OPBiz.SetCout("Id", Id, "Praises"); if (res > 0) { resultMode.Code = 11; resultMode.Data = res.ToString(); resultMode.Msg = "统计成功"; } else { resultMode.Code = -13; resultMode.Data = "0"; resultMode.Msg = "统计失败!"; } break; case "CallCount": //呼叫量加1 Id = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString()); res = OPBiz.SetCout("Id", Id, "CallCount"); if (res > 0) { resultMode.Code = 11; resultMode.Data = res.ToString(); resultMode.Msg = "统计成功"; } else { resultMode.Code = -13; resultMode.Data = "0"; resultMode.Msg = "统计失败!"; } break; } } catch (Exception ex) { resultMode.Code = -11; resultMode.Data = ex.ToString(); } context.Response.Write(JsonHelper.ToJson(resultMode, true)); context.Response.End(); }
public JsonResult EditInfo(TS_Shop DitModle) { HttpReSultMode ReSultMode = new HttpReSultMode(); bool IsAdd = false; if (DitModle.Details != null) { DitModle.Details = DitModle.Details.Replace("<", "<").Replace(">", ">"); } else { DitModle.Details = ""; } DitModle.UpdateTime = DateTime.Now; if (DitModle.Longitude != null && DitModle.Latitude != null)//geohash编码 { double Latitude = double.Parse(DitModle.Latitude.ToString()); double Longitude = double.Parse(DitModle.Longitude.ToString()); DitModle.geohash = Geohash.Encode(Latitude, Longitude); } if (!(DitModle.Id != null && !DitModle.Id.ToString().Equals("00000000-0000-0000-0000-000000000000")))//id为空,是添加 { IsAdd = true; } if (IsAdd) { #region 初始化 DitModle.Id = Guid.NewGuid(); DitModle.CreateTime = DateTime.Now; DitModle.CreateManId = UserData.Id; DitModle.Praises = 0; DitModle.CallCount = 0; DitModle.Clicks = 0; DitModle.States = 0; DitModle.isDeleted = false; DitModle.isValid = 1; DitModle.Star = 1; #endregion try { OPBiz.Add(DitModle); ReSultMode.Code = 11; ReSultMode.Data = DitModle.Id.ToString(); ReSultMode.Msg = "添加成功"; } catch (Exception e) { ReSultMode.Code = -11; ReSultMode.Data = e.ToString(); ReSultMode.Msg = "添加失败"; } } else { DitModle.WhereExpression = TS_ShopSet.Id.Equal(DitModle.Id); var mqlO = TS_ShopSet.SelectAll().Where(TS_ShopSet.Id.Equal(DitModle.Id)); TS_Shop modelOld = OPBiz.GetEntity(mqlO);//旧数据 #region 能修改的数据 DitModle.CreateTime = modelOld.CreateTime; DitModle.CreateManId = modelOld.CreateManId; DitModle.Praises = modelOld.Praises; DitModle.CallCount = modelOld.CallCount; DitModle.Clicks = modelOld.Clicks; DitModle.States = modelOld.States; DitModle.isDeleted = modelOld.isDeleted; DitModle.isValid = modelOld.isValid; DitModle.Star = modelOld.Star; #endregion //TS_ShopModle.ChangedMap.Remove("doctorid");//移除主键值 if (OPBiz.Update(DitModle) > 0) { ReSultMode.Code = 11; ReSultMode.Data = ""; ReSultMode.Msg = "修改成功"; } else { ReSultMode.Code = -13; ReSultMode.Data = ""; ReSultMode.Msg = "修改失败"; } } return(Json(ReSultMode, JsonRequestBehavior.AllowGet)); }
public t_user_pos SavePos() { try { #region Save t_country,t_province,t_city,t_district,t_town t_country country = db.t_country.Where(c => c.name == this.request.Country).FirstOrDefault(); if (country == null) { country = new t_country() { id = 0, name = this.request.Country, }; db.t_country.Add(country); db.SaveChanges(); } t_province province = db.t_province.Where(p => p.name == this.request.Province).FirstOrDefault(); if (province == null) { province = new t_province() { id = 0, country_id = country.id, name = this.request.Province, }; db.t_province.Add(province); db.SaveChanges(); } t_city city = db.t_city.Where(c => c.name == this.request.City).FirstOrDefault(); if (city == null) { city = new t_city() { id = 0, province_id = province.id, name = this.request.City, }; db.t_city.Add(city); db.SaveChanges(); } t_district district = db.t_district.Where(p => p.name == this.request.District).FirstOrDefault(); if (district == null) { district = new t_district() { id = 0, city_id = city.id, name = this.request.District, }; db.t_district.Add(district); db.SaveChanges(); } t_town town = db.t_town.Where(p => p.name == this.request.Town).FirstOrDefault(); if (town == null) { town = new t_town() { id = 0, district_id = district.id, name = this.request.Town, }; db.t_town.Add(town); db.SaveChanges(); } #endregion //t_user_pos upos = db.t_user_pos.Where(u => u.user_id == this.request.UserId && // u.country_id == country.id && // u.province_id == province.id && // u.city_id == city.id && // u.district_id == district.id && // u.pos_details == this.request.Details // ).FirstOrDefault(); t_user_pos upos = db.t_user_pos.Where(u => u.user_id == this.request.UserId && u.lon == request.Longitude && u.lat == request.Latitude ).FirstOrDefault(); if (upos == null) { upos = new t_user_pos() { id = 0, create_date = DateTime.Now, update_date = DateTime.Now, geohash_key = Geohash.Encode(this.request.Latitude, this.request.Longitude), lat = this.request.Latitude, lon = this.request.Longitude, pos_details = this.request.Details, user_id = this.request.UserId, city_id = city.id, country_id = country.id, district_id = district.id, province_id = province.id, coordinate_type = request.CoorType, location_type = request.LocationType, Location_where = request.LocationWhere, radius = request.Radius, town_id = town.id, }; db.t_user_pos.Add(upos); } else { upos.update_date = DateTime.Now; } db.SaveChanges(); return(upos); } catch (Exception ex) { string currentParams = Newtonsoft.Json.JsonConvert.SerializeObject(request); LogHelper.Error(currentParams + "___" + ex.ToString(), typeof(SetUserPos)); } return(null); }
public void Point_To_Geohash() { Point p = new Point(-97.0, 32.0); string hash = Geohash.FromPoint(p, 5); }
//[Authorize(AuthenticationSchemes = "jwt")] public APIResult GetPagedList([FromBody] GetPagedListArgsModel args) { args.OrderName = args.OrderName ?? ""; if (args.PageSize <= 0) { args.PageSize = 10; } if (args.PageIndex == 0) { args.PageIndex = 1; } var query = db.Query <Shop>() .Where(m => !m.IsDel); if (args.Latitude.HasValue && args.Longitude.HasValue) { //6 范围在±0.61KM var geohash = Geohash.Encode(args.Latitude.Value, args.Longitude.Value, 6); var areas = GetGeoHashExpand(geohash); query = query.Where(m => m.GeoHash.StartsWith(areas[0]) || m.GeoHash.StartsWith(areas[1]) || m.GeoHash.StartsWith(areas[2]) || m.GeoHash.StartsWith(areas[3]) || m.GeoHash.StartsWith(areas[4]) || m.GeoHash.StartsWith(areas[5]) || m.GeoHash.StartsWith(areas[6]) || m.GeoHash.StartsWith(areas[7]) ); } var list = query .Select(m => new RowItem() { AddIp = m.AddIp, AddTime = m.AddTime, AddUser = m.AddUser, Flag = m.Flag, Id = m.Id, Address = m.Address, AddressGuide = m.AddressGuide, Detail = m.Detail, IsDel = m.IsDel, Latitude = m.Latitude, Longitude = m.Longitude, Name = m.Name, OpenTime = m.OpenTime, ScoreValue = m.ScoreValue, Tel = m.Tel, UsePerUser = m.UsePerUser, Cover = m.Cover, Logo = m.Logo }) .ToPagedList(args.PageIndex, args.PageSize); return(Success(new GetPagedListModel() { PageIndex = list.PageIndex, PageSize = list.PageSize, TotalCount = list.TotalItemCount, Items = list.Where(r => r.IsShowApplets == true).ToList() })); }