/// <summary> /// 将车机坐标转换成与地图显示一致的 /// </summary> /// <param name="lng"></param> /// <param name="lat"></param> /// <returns></returns> public static PointModel NetDecryFixTrue(double lng, double lat) { Rectify.Wgs84_To_Gcj02(ref lat, ref lng); //NetDecry.Fix(ref lng, ref lat, true); PointModel point = new PointModel() { Longitude = lng, Latitude = lat }; return(point); }
/// <summary> /// 高德地图坐标和车机坐标互转 /// 地图上获取的是地图坐标,存入数据库时需要转换成车机坐标 /// 数据库查询出来的坐标是车机坐标,地图显示时候需要转换成地图坐标 /// </summary> /// <param name="efType">坐标数据是圆形或者矩形、多边形,圆形和矩形、多边形的存储方式有别,需要分开处理</param> /// <param name="efInfo">坐标数据</param> /// <param name="changeType">1--地图坐标转车机坐标,2--车机坐标转地图坐标</param> /// <returns></returns> public static string ChangeCoordinateSystem(int?efType, string efInfo, int changeType) { string[] _tempEfInfo; string _rsEfInfo = ""; if (efType == 1) //圆形 { _tempEfInfo = efInfo.Split(';'); for (int i = 0; i < _tempEfInfo.Length - 1; i++) //最后一个是圆形半径,去掉 { string[] _tempCoordinate = _tempEfInfo[i].Split(','); double _lng = double.Parse(_tempCoordinate[0]); double _lat = double.Parse(_tempCoordinate[1]); if (changeType == 1) { //NetDecry.Fix(ref _lng, ref _lat, false); Rectify.Gcj02_To_Wgs84(ref _lat, ref _lng); } //将地图坐标置成车机坐标 else if (changeType == 2) { //NetDecry.Fix(ref _lng, ref _lat, true); Rectify.Wgs84_To_Gcj02(ref _lat, ref _lng); } //将车机坐标置成地图坐标 _rsEfInfo += _lng + "," + _lat + ";"; } _rsEfInfo += _tempEfInfo[_tempEfInfo.Length - 1]; //加上半径信息 } else if (efType == 2 || efType == 3) //矩形、多边形 { _tempEfInfo = efInfo.Split(';'); for (int i = 0; i < _tempEfInfo.Length; i++) { string[] _tempCoordinate = _tempEfInfo[i].Split(','); double _lng = double.Parse(_tempCoordinate[0]); double _lat = double.Parse(_tempCoordinate[1]); if (changeType == 1) { //NetDecry.Fix(ref _lng, ref _lat, false); Rectify.Gcj02_To_Wgs84(ref _lat, ref _lng); } //将地图坐标置成车机坐标 else if (changeType == 2) { //NetDecry.Fix(ref _lng, ref _lat, true); Rectify.Wgs84_To_Gcj02(ref _lat, ref _lng); } //将车机坐标置成地图坐标 _rsEfInfo += _lng + "," + _lat + ";"; } _rsEfInfo = _rsEfInfo.Substring(0, _rsEfInfo.Length - 1); //去掉最后一个";" } return(_rsEfInfo); }
public static SelectResult <MapLinesEditModel> GetMapLinesByID(int id) { List <SqlParameter> paras = new List <SqlParameter>() { new SqlParameter() { ParameterName = "@ID", SqlDbType = SqlDbType.BigInt, }, }; paras[0].Value = id; string sql = @"SELECT ID ,LinesType ,LinesName ,StartTime ,EndTime ,Remark FROM dbo.MapLinesList WHERE Status=0 AND ID=@ID"; List <MapLinesEditModel> list = ConvertToList <MapLinesEditModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, sql, paras.ToArray())); MapLinesEditModel data = null; string msg = string.Empty; if (list == null) { msg = PromptInformation.DBError; } else if (list.Count == 0) { msg = PromptInformation.NotExists; } else { List <SqlParameter> detailParas = new List <SqlParameter>() { new SqlParameter() { ParameterName = "@ID", SqlDbType = SqlDbType.BigInt, }, }; detailParas[0].Value = id; string detailSql = @"SELECT OrderID ,Latitude ,Longitude ,RoadWidth ,IsCheckTime, MaxSecond,MinSecond,IsCheckSpeed,SpeedLimit,OverSpeedDuration ,IsSouthLatitude,IsWestLongitude FROM dbo.MapLinesDetails WHERE LinesID=@ID"; List <MapLinesDetailsEditModel> detailList = ConvertToList <MapLinesDetailsEditModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, detailSql, detailParas.ToArray())); if (detailList != null && detailList.Count != 0) { string points = string.Empty; for (int i = 0; i < detailList.Count; i++) { //纠偏 double lng = double.Parse(detailList[i].Longitude.ToString()); double lat = double.Parse(detailList[i].Latitude.ToString()); //NetDecry.Fix(ref lng, ref lat, true); Rectify.Wgs84_To_Gcj02(ref lat, ref lng); detailList[i].Longitude = (float)lng; detailList[i].Latitude = (float)lat; points = points + lng.ToString() + ","; points = points + lat.ToString() + ","; } list[0].MapLinesPoints = points; list[0].MapLinesDetails = detailList; } data = list[0]; } return(new SelectResult <MapLinesEditModel>() { DataResult = data, Message = msg }); }
public static SelectResult <MapRegionsEditModel> GetMapRegionsByID(int id, int regionsType) { List <SqlParameter> paras = new List <SqlParameter>() { new SqlParameter() { ParameterName = "@ID", SqlDbType = SqlDbType.BigInt, }, }; paras[0].Value = id; string sql = string.Empty; if (regionsType == 1) { sql = @"SELECT ID,RegionsType, RegionsName,CenterLatitude,CenterLongitude,Radius, CAST(StartDate AS CHAR(10)) AS StartDate, CAST(StartTime AS CHAR(8)) AS StartTime, CAST(EndDate AS CHAR(10)) AS EndDate, CAST(EndTime AS CHAR(8)) AS EndTime, Periodic, SpeedLimit, OverSpeedDuration FROM dbo.MapRegionsList WHERE Status=0 AND ID=@ID"; } if (regionsType == 2) { sql = @"SELECT ID,RegionsType, RegionsName,LeftUpperLatitude,LeftUpperLongitude,RightLowerLatitude,RightLowerLongitude, CAST(StartDate AS CHAR(10)) AS StartDate, CAST(StartTime AS CHAR(8)) AS StartTime, CAST(EndDate AS CHAR(10)) AS EndDate, CAST(EndTime AS CHAR(8)) AS EndTime, Periodic, SpeedLimit, OverSpeedDuration FROM dbo.MapRegionsList WHERE Status=0 AND ID=@ID"; } if (regionsType == 3) { sql = @"SELECT MPL.ID,MPL.RegionsType, MPL.RegionsName, CAST(MPL.StartDate AS CHAR(10)) AS StartDate, CAST(MPL.StartTime AS CHAR(8)) AS StartTime, CAST(MPL.EndDate AS CHAR(10)) AS EndDate, CAST(MPL.EndTime AS CHAR(8)) AS EndTime, MPL.Periodic, MPL.SpeedLimit, MPL.OverSpeedDuration,MPD.Latitude,MPD.Longitude,MPD.OrderID FROM dbo.MapRegionsList MPL LEFT JOIN dbo.MapRegionsDetails MPD ON MPL.ID=MPD.RegionsID WHERE MPL.Status=0 AND MPL.ID=@ID"; } List <MapRegionsEditModel> list = ConvertToList <MapRegionsEditModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, sql, paras.ToArray())); MapRegionsEditModel data = null; string msg = string.Empty; if (list == null) { msg = PromptInformation.DBError; } else if (list.Count == 0) { msg = PromptInformation.NotExists; } else { if (regionsType == 1 || regionsType == 2) { //纠偏 double centerLng = double.Parse(list[0].CenterLongitude.ToString()); double centerLat = double.Parse(list[0].CenterLatitude.ToString()); //NetDecry.Fix(ref centerLng, ref centerLat, true); Rectify.Wgs84_To_Gcj02(ref centerLat, ref centerLng); double leftLng = double.Parse(list[0].LeftUpperLongitude.ToString()); double leftLat = double.Parse(list[0].LeftUpperLatitude.ToString()); double rightLng = double.Parse(list[0].RightLowerLongitude.ToString()); double rightLat = double.Parse(list[0].RightLowerLatitude.ToString()); Rectify.Wgs84_To_Gcj02(ref leftLat, ref leftLng); Rectify.Wgs84_To_Gcj02(ref rightLat, ref rightLng); //NetDecry.Fix(ref leftLng, ref leftLat, true); //NetDecry.Fix(ref rightLng, ref rightLat, true); list[0].CenterLongitude = (float)centerLng; list[0].CenterLatitude = (float)centerLat; list[0].LeftUpperLongitude = (float)leftLng; list[0].LeftUpperLatitude = (float)leftLat; list[0].RightLowerLongitude = (float)rightLng; list[0].RightLowerLatitude = (float)rightLat; data = list[0]; } else { int len = list.Count; //List<string> points = new List<string>(); string points = string.Empty; for (int i = 0; i < len; i++) { //纠偏 double lng = double.Parse(list[i].Longitude.ToString()); double lat = double.Parse(list[i].Latitude.ToString()); //NetDecry.Fix(ref lng, ref lat, true); Rectify.Wgs84_To_Gcj02(ref lat, ref lng); points = points + lng.ToString() + ","; points = points + lat.ToString() + ","; //points.Add(list[i].Longitude.ToString()); //points.Add(list[i].Latitude.ToString()); } list[0].RePolygonList = points; data = list[0]; } } return(new SelectResult <MapRegionsEditModel>() { DataResult = data, Message = msg }); }