public string Execute(Hashtable params_ht) { Hashtable res = params_ht; if (res["Latitude"] == null || res["Longitude"] == null || res["Latitude"].ToString().Trim().Length <= 0 || res["Longitude"].ToString().Trim().Length <= 0) { return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整")); } else { weidu = res["Latitude"].ToString().Trim(); jingdu = res["Longitude"].ToString().Trim(); Hashtable location = new Hashtable(); location["ADDRESS"] = SiteHelper.GetLocationByGPS(weidu, jingdu); if (res["Client"] != null && "iOS" == res["Client"].ToString()) { LatLng latlng = SiteHelper.GetBaiduByGPS(jingdu, weidu); location["ADDRESS"] = SiteHelper.GetLocationByGPS(latlng.longitude.ToString(), latlng.latitude.ToString(), "gcj02ll"); } location["LATITUDE"] = weidu; location["LONGITUDE"] = jingdu; return(SiteHelper.GetJsonFromHashTable(location, "success", "获取数据成功", "LocationInfo")); } }
/// <summary> /// 获取附近车辆信息 /// </summary> /// <param name="context"></param> private void GetNearVehicles(HttpContext context) { double km = 100; int pageNum = 100; int currentPage = 1; string weidu = string.Empty; string jingdu = string.Empty; if (!string.IsNullOrEmpty(SiteHelper.GetAppsetString("NearVehicleKM"))) { km = double.Parse(SiteHelper.GetAppsetString("NearVehicleKM")); } if (!string.IsNullOrEmpty(SiteHelper.GetAppsetString("PageNum"))) { pageNum = int.Parse(SiteHelper.GetAppsetString("PageNum")); } if (context.Request["Latitude"] == null || context.Request["Longitude"] == null || context.Request["PageNum"] == null || context.Request["CurrentPage"] == null || context.Request["Latitude"].ToString().Trim().Length <= 0 || context.Request["Longitude"].ToString().Trim().Length <= 0 || context.Request["PageNum"].ToString().Trim().Length <= 0 || context.Request["CurrentPage"].ToString().Trim().Length <= 0) { context.Response.Write(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整")); } else { try { //pageNum = int.Parse(res["PageNum"].ToString().Trim()); currentPage = int.Parse(context.Request["CurrentPage"].ToString().Trim()); weidu = context.Request["Latitude"].ToString().Trim(); jingdu = context.Request["Longitude"].ToString().Trim(); } catch { context.Response.Write(SiteHelper.GetJsonFromHashTable(null, "faild", "数据格式不正确")); context.Response.End(); } VehicleManager vm = new VehicleManager(); DataTable vehicles = vm.GetNearVehicles(km, weidu, jingdu, currentPage, pageNum); if (vehicles == null || vehicles.Rows.Count <= 0) { context.Response.Write(SiteHelper.GetJsonFromHashTable(null, "faild", "亲,没有数据了")); context.Response.End(); } else { foreach (DataRow dr in vehicles.Rows) { dr["ThumbImageUrl"] = SiteHelper.GetFileServer() + dr["ThumbImageUrl"].ToString(); decimal electricity = 0; decimal.TryParse(dr["Electricity"].ToString(), out electricity); int dianliang = Decimal.ToInt32(electricity); dr["Electricity"] = dianliang + "%"; string lng = dr["Longitude"].ToString(); string lat = dr["Latitude"].ToString(); if (!string.IsNullOrEmpty(lng) && !string.IsNullOrEmpty(lat)) { LatLng latlng = SiteHelper.GetBaiduByGPS(lat, lng); if (latlng != null) { dr["Longitude"] = latlng.longitude; dr["Latitude"] = latlng.latitude; if (dr["Address"].ToString().Trim().Length <= 0) { dr["Address"] = SiteHelper.GetLocationByGPS(dr["Latitude"].ToString(), dr["Longitude"].ToString()); } } } } context.Response.Write(JsonHelper.DataTableToJson("success", "获取数据成功", vehicles, "VehicleInfo")); } } }