Beispiel #1
0
        private void GetDeviceTracking(int DeviceID)
        {
            MG_DAL.SQLServerOperating sqlHelper = new MG_DAL.SQLServerOperating();
            string strSql = "select d.DeviceID,d.SerialNumber,DeviceName,l.OLat,l.OLng,l.LastCommunication DeviceDate,l.Speed,l.Course,l.DataContext from devices d inner join LKLocation l on l.DeviceID=d.DeviceiD where d.DeviceID =@DeviceID and d.deleted=0";// model=213 and

            dic = sqlHelper.Selects(strSql, new SqlParameter[] { new SqlParameter("DeviceID", DeviceID) }).toDictionary();

            Geocoding geo = new Amap();
            Gps       gps = geo.Translate(dic["OLat"], dic["OLng"]);

            //Gps gps = Utils.gps84_To_Gcj02(dic["OLat"], dic["OLng"]);
            dic["OLat"]       = gps.getWgLat().ToString();
            dic["OLng"]       = gps.getWgLon().ToString();
            dic["Address"]    = gps.Address;
            dic["CourseName"] = Utils.GetCoureName(dic["Course"]);
            var dc         = dic["DataContext"];
            var doorStatus = "未知";

            if (dc.Split('-').Length > 3 && !string.IsNullOrEmpty(dc.Split('-')[3]))
            {
                dc = dc.Split('-')[3];
                if (dc.Equals("0"))
                {
                    doorStatus = "打开";
                }
                else
                {
                    doorStatus = "关闭";
                }
            }
            dic["DataContext"] = doorStatus;// = dic["DataContext"].Split('-')[3]; //0--- 主电断开, 1-----主电连接
            Response.Write(Utils.ToJson(dic));
            Response.End();
        }
Beispiel #2
0
        /// <summary>
        /// BD-09 坐标转换成 Wgs84 坐标
        /// </summary>
        /// <param name="bd_lat"></param>
        /// <param name="bd_lon"></param>
        /// <returns></returns>
        public static Gps BD09_To_Gps84(double bd_lat, double bd_lon)
        {
            Gps gcj02 = BD09_To_Gcj02(bd_lat, bd_lon);
            Gps map84 = Gcj_To_Gps84(gcj02.getWgLat(),
                                     gcj02.getWgLon());

            return(map84);
        }
Beispiel #3
0
        /// <summary>
        /// 火星坐标系 (GCJ-02) to Wgs84
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        /// <returns></returns>
        public static Gps Gcj_To_Gps84(double lat, double lon)
        {
            Gps    gps       = Transform(lat, lon);
            double lontitude = lon * 2 - gps.getWgLon();
            double latitude  = lat * 2 - gps.getWgLat();

            return(new Gps(latitude, lontitude));
        }
Beispiel #4
0
        /// <summary>
        /// BD-09 坐标转换成 Wgs84 坐标
        /// </summary>
        /// <param name="bd_lat"></param>
        /// <param name="bd_lon"></param>
        /// <returns></returns>
        public static Gps Gps84_To_BD09(double bd_lat, double bd_lon)
        {
            Gps gcj02 = Gps84_To_Gcj02(bd_lat, bd_lon);
            Gps map84 = Gcj02_To_Bd09(gcj02.getWgLat(),
                                      gcj02.getWgLon());

            return(map84);
        }
Beispiel #5
0
 private void btn_WgstoBD09_Click(object sender, EventArgs e)
 {
     try
     {
         double lat     = double.Parse(this.tbx_lat.Text.Trim());
         double lng     = double.Parse(this.tbx_lng.Text.Trim());
         Gps    gpsData = MapConvertHelper.Gps84_To_BD09(lat, lng);
         this.tbx_return.Text = gpsData.getWgLat().ToString() + "," + gpsData.getWgLon().ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Beispiel #6
0
        private string GetHistory(int deviceid, string startdate, string enddate)
        {
            var    list        = new List <Dictionary <string, string> >();
            string speedfilter = "2";

            if (string.IsNullOrEmpty(deviceid.ToString()) || string.IsNullOrEmpty(startdate) || string.IsNullOrEmpty(enddate))
            {
                return(Utils.ToJson(list));
            }
            if (string.IsNullOrEmpty(speedfilter))
            {
                speedfilter = Utils.SpeedFilter.toStringEmpty();
            }
            try
            {
                DateTime startTime = Convert.ToDateTime(startdate);
                DateTime endTime   = Convert.ToDateTime(enddate);
                if (startTime >= endTime)
                {
                    return(Utils.ToJson(list));
                }
                TimeSpan ts   = endTime - startTime;
                double   days = Math.Ceiling(ts.TotalDays);
                //一次最多只能看5天的数据
                if (days > 5)
                {
                    return(Utils.ToJson(list));
                }
                string        DataBaseBefore = "YWData";// ConfigurationManager.AppSettings["DataBaseName"].ToStringEmpty();
                StringBuilder strSql         = new StringBuilder();

                string startTimeUtc = startTime.AddHours(-8).ToString("yyyy-MM-dd HH:mm:ss");
                string endTimeUtc   = endTime.AddHours(-8).ToString("yyyy-MM-dd HH:mm:ss");

                strSql.Append(" select DeviceTime, OLat, OLng, Speed, Course from ( ");
                string where = " where speed > @speedfilter and deviceid=@deviceid and DeviceUTCTime>@startTimeUtc and DeviceUTCTime<@endTimeUtc";
                for (int i = 0; i < days; i++)
                {
                    string DateBase  = DataBaseBefore + startTime.ToString("yyyyMM");
                    int    TableName = Convert.ToInt32(startTime.ToString("dd"));
                    strSql.Append("select dateadd(HH,8,DeviceUTCTime)DeviceTime, OLat, OLng, Speed, Course from  [" + DateBase + "].[dbo].[Location" + TableName + @"]");
                    strSql.Append(where);
                    if (i != days - 1)
                    {
                        strSql.Append(" union all ");
                    }
                    startTime = startTime.AddDays(1);
                }
                strSql.Append(" )t order by DeviceTime");
                SQLServerOperating s     = new SQLServerOperating();
                string             model = s.Select("select di.DataText from Devices d inner join Dictionary di on di.DataValue=d.Model where DeviceID=@DeviceID", new SqlParameter[] { new SqlParameter("DeviceID", deviceid) });
                if (model.EndsWith("W") || model.EndsWith("WD") || model.EndsWith("WF"))
                {
                    speedfilter = "-1";
                }
                SqlParameter[] pars = new SqlParameter[] {
                    new SqlParameter("speedfilter", speedfilter),
                    new SqlParameter("deviceid", deviceid),
                    new SqlParameter("startTimeUtc", startTimeUtc),
                    new SqlParameter("endTimeUtc", endTimeUtc)
                };

                DataTable dt = s.Selects(strSql.ToString(), pars);
                //List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                Geocoding geo = new Amap();
                foreach (DataRow row in dt.Rows)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    foreach (DataColumn dc in dt.Columns)
                    {
                        dic[dc.ColumnName] = row[dc.ColumnName].toStringEmpty();
                    }
                    Gps gps       = geo.Translate(dic["OLat"], dic["OLng"], false);
                    var listWhere = list.Where(l => l.ContainsValue(gps.getWgLat().ToString()) && l.ContainsValue(gps.getWgLon().ToString()));
                    if (listWhere.Count() > 0)
                    {
                        continue;
                    }
                    dic["OLat"] = gps.getWgLat().toStringEmpty();
                    dic["OLng"] = gps.getWgLon().toStringEmpty();
                    list.Add(dic);
                }
                return(Utils.ToJson(list));
            }
            catch (Exception ex)
            {
                Utils.log("GetHistoryLocus Error2:" + ex.Message + ",堆栈信息:" + ex.StackTrace + "," + deviceid + "-" + startdate + "-" + enddate);
                return(Utils.ToJson(list));
            }
        }