Example #1
0
        public string GetAddress(Gps bdGps)
        {
            try
            {
                Mgoo.Position.IGeocoding geo = new Mgoo.Position.Geocod.Baidu();
                return(geo.GetAddress(new Mgoo.Position.Point(bdGps.getWgLat(), bdGps.getWgLon())));

                //POIService.POIServiceSoapClient poi = new POIService.POIServiceSoapClient();
                //return poi.GetAddressByLatlng(Convert.ToDecimal(bdGps.getWgLat()), Convert.ToDecimal(bdGps.getWgLon()), "BAIDU", "ZH-CN");

                #region 利用百度地址API获取地址 - 没用了

                /*MG_DAL.MgoogpsWebClient wc = new MG_DAL.MgoogpsWebClient();
                 * wc.RequestUrl = "http://api.map.baidu.com/geocoder/v2/?ak=PFEwxiwsyv4GjEQcZrNZS0NsIkEvU8TL&location=" + bdGps.getWgLat() + "," + bdGps.getWgLon() + "&output=json&pois=0";
                 * wc.RequestMethodType = "GET";
                 * string jsonLocation = wc.RequestSend();
                 * JavaScriptSerializer js = new JavaScriptSerializer();
                 * BaiduAddress bdLocation = js.Deserialize<BaiduAddress>(jsonLocation);
                 * return bdLocation.Result.Formatted_address;*/
                #endregion
            }
            catch (Exception ex)
            {
                Utils.log("EvilTransform.cs>GetAddress(baidu):" + ex.Message);
                return("未知.");
            }
        }
Example #2
0
            /// <summary>
            /// (BD-09)-->84
            /// </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 = PositionUtil.bd09_To_Gcj02(bd_lat, bd_lon);
                Gps map84 = PositionUtil.gcj_To_Gps84(gcj02.getWgLat(), gcj02.getWgLon());

                return(map84);
            }
Example #3
0
 /// <summary>
 /// 根据IMEI获取历史数据
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="StartTime"></param>
 /// <param name="EndTime"></param>
 /// <returns></returns>
 public List <History> GetHistory(string ID, string StartTime, string EndTime)
 {
     try
     {
         MgoogpsWebClient mwc = new MgoogpsWebClient();
         mwc.RequestMethodName  = "/service/gethistory/?param=id," + ID + "&starttime," + Convert.ToDateTime(StartTime).Ticks + "&endtime," + Convert.ToDateTime(EndTime).Ticks;
         mwc.RequestPostData    = new byte[0];
         mwc.RequestContentType = "application/x-www-form-urlencoded";
         string data             = mwc.RequestSend();
         JavaScriptSerializer js = new JavaScriptSerializer();
         js.MaxJsonLength = Int32.MaxValue;
         List <History> his = js.Deserialize <List <History> >(data);
         List <History> retData = new List <History>();
         double         lat = 0, lng = 0;
         foreach (History item in his)
         {
             if (!string.IsNullOrWhiteSpace(item.Lat) || !string.IsNullOrWhiteSpace(item.Lon))
             {
                 Gps g = EvilTransform.PositionUtil.gcj02_To_Bd09(Convert.ToDouble(item.Lat), Convert.ToDouble(item.Lon));
                 lat      = g.getWgLat();
                 lng      = g.getWgLon();
                 item.Lat = lat.ToString(); item.Lon = lng.ToString();
                 retData.Add(item);
             }
         }
         return(retData);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
            /// <summary>
            ///  火星坐标系 (GCJ-02) to 84 * *
            /// </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));
            }
Example #5
0
        /// <summary>
        /// 根据IMEI号获取设备信息(实时跟踪也用此方法)
        /// </summary>
        /// <param name="Imei"></param>
        /// <returns></returns>
        public string GetDeviceData(string Imei)
        {
            try
            {
                MgoogpsWebClient mwc = new MgoogpsWebClient();
                mwc.RequestMethodName = "/service/getlocationbydevice/?id=" + Imei;
                mwc.RequestMethodType = "GET";
                string jsonStr                   = mwc.RequestSend();
                JavaScriptSerializer jss         = new JavaScriptSerializer();
                Entity.DeviceDetail  device      = jss.Deserialize <Entity.DeviceDetail>(jsonStr);
                DateTime             connectTime = Convert.ToDateTime(device.ConnectTime);

                if (connectTime < Convert.ToDateTime("0010-01-01"))
                {
                    device.DeviceStatus = (int)DeviceStatus.未激活 + "," + device.Speed;
                }
                else if ((DateTime.Now - connectTime).TotalMinutes > Utils.OffLineMinute)
                {
                    device.DeviceStatus = (int)DeviceStatus.离线 + "," + Convert.ToInt32((DateTime.Now - connectTime).TotalMinutes);
                }
                else if (Convert.ToInt32(device.Speed) > 0)
                {
                    device.DeviceStatus = (int)DeviceStatus.行驶 + "";
                }
                else if (Convert.ToInt32(device.Speed) <= 0 && (DateTime.Now - connectTime).TotalMinutes <= Utils.OffLineMinute)
                {
                    device.DeviceStatus = (int)DeviceStatus.停止 + "," + (DateTime.Now - Convert.ToDateTime(connectTime)).TotalMinutes;;
                }
                double lat = 0, lng = 0;
                if (!string.IsNullOrWhiteSpace(device.Lbs.toStringEmpty()))
                {
                    Dictionary <string, object> lbs = (Dictionary <string, object>)device.Lbs;
                    if (lbs["time"].toStringEmpty().toDateTime() > device.ConnectTime.toDateTime())
                    {
                        device.Lat = lbs["lat"].toStringEmpty(); device.Lon = lbs["lon"].toStringEmpty();
                    }
                    else if (device.Lat.toDouble() == 0.00 || device.Lon.toDouble() == 0.00)
                    {
                        device.Lat = lbs["lat"].toStringEmpty(); device.Lon = lbs["lon"].toStringEmpty();
                    }
                    device.DeviceTime = lbs["time"].toStringEmpty().toDateTime().AddHours(8).ToString();
                }
                Gps gps = EvilTransform.PositionUtil.gcj02_To_Bd09(double.Parse(device.Lat), double.Parse(device.Lon));
                lat        = gps.getWgLat();
                lng        = gps.getWgLon();
                device.Lat = lat + ""; device.Lon = lng + "";

                device.Address = bllGetAddress(double.Parse(device.Lat), double.Parse(device.Lon));
                return(jss.Serialize(device));
            }
            catch (Exception ex)
            {
                Utils.log("GetDeviceData方法出错:" + ex.Message + ", 堆栈信息:" + ex.StackTrace);
                throw ex;
            }
        }
Example #6
0
        /// <summary>
        /// 获取用户下所有设备的报警信息
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List <Alarms> GetAlarms(string UserID)
        {
            MgoogpsWebClient mwc = new MgoogpsWebClient();

            mwc.RequestMethodName = "/service/getalarms/?user="******"GET";
            string jsonStr = mwc.RequestSend();
            JavaScriptSerializer js = new JavaScriptSerializer();
            List <Alarms>        list = js.Deserialize <List <Alarms> >(jsonStr);
            double lat = 0, lng = 0;

            for (int i = 0; i < list.Count; i++)
            {
                Gps g = EvilTransform.PositionUtil.gcj02_To_Bd09(Convert.ToDouble(list[i].Lat), Convert.ToDouble(list[i].Lon));
                lat         = g.getWgLat();
                lng         = g.getWgLon();
                list[i].Lat = lat.ToString(); list[i].Lon = lng.ToString();
            }
            return(list);
        }
Example #7
0
        public string GetAddress(Gps gps)
        {
            try
            {
                Mgoo.Position.IGeocoding geo = new Mgoo.Position.Geocod.Amap();
                return(geo.GetAddress(new Mgoo.Position.Point(gps.getWgLat(), gps.getWgLon())));

                //if (string.IsNullOrEmpty( this.key))
                //{
                //    this.key = Utils.GetAmapKey();
                //}
                //POIService.POIServiceSoapClient poi = new POIService.POIServiceSoapClient();
                //return poi.GetAddressByLatlng(Convert.ToDecimal(gps.getWgLat()), Convert.ToDecimal(gps.getWgLon()), "AMAP", "ZH-CN");

                #region 利用高德地图获取中文详细地址- 没用了

                /*string jsonLocation = "";
                 * MG_DAL.MgoogpsWebClient wc = new MG_DAL.MgoogpsWebClient();
                 * wc.RequestMethodType = "GET";
                 * wc.RequestUrl = " http://restapi.amap.com/v3/geocode/regeo?output=json&location=" + gps.getWgLon() + "," + gps.getWgLat() + "&key=" + _key + "&radius=1000&extensions=base";
                 * jsonLocation = wc.RequestSend();
                 * //"{\"status\":\"1\",\"info\":\"OK\",\"infocode\":\"10000\",\"regeocode\":{\"formatted_address\":\"广东省中山市南朗镇华峰路\",\"addressComponent\":{\"country\":\"中国\",\"province\":\"广东省\",\"city\":\"中山市\",\"citycode\":\"0760\",\"district\":[],\"adcode\":\"442000\",\"township\":\"南朗镇\",\"towncode\":\"442000113000\",\"neighborhood\":{\"name\":[],\"type\":[]},\"building\":{\"name\":[],\"type\":[]},\"streetNumber\":{\"street\":\"华峰路\",\"number\":\"15号\",\"location\":\"113.509635,22.5109078\",\"direction\":\"东北\",\"distance\":\"31.9644\"},\"businessAreas\":[[]]}}}"
                 * Dictionary<string, object> addressDic = Utils.ToObjects<Dictionary<string, object>>(jsonLocation);
                 * if (addressDic["status"].Equals("1"))
                 * {
                 *  return (addressDic["regeocode"] as Dictionary<string, object>)["formatted_address"].toStringEmpty();
                 * }
                 * else
                 * {
                 *  return "未知";
                 * }*/
                #endregion
            }
            catch (Exception ex)
            {
                Utils.log("EvilTransform.cs>GetAddress(amap):" + ex.Message);
                return("未知.");
            }
        }
Example #8
0
        /// <summary>
        /// 根据用户ID获取设备列表,包括该用户ID的报警消息条目
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="msgCount"></param>
        /// <returns></returns>
        public List <Entity.Devices> GetDevicesByUserID_Bll(String UserID, ref string msgCount)
        {
            List <Entity.Devices> deviceList = new List <Entity.Devices>();

            try
            {
                MgoogpsWebClient mwc = new MgoogpsWebClient();
                mwc.RequestMethodName = "/service/getlocations?user="******"GET";
                String jsonStr = mwc.RequestSend();
                JavaScriptSerializer        js  = new JavaScriptSerializer();
                Dictionary <string, object> dic = js.Deserialize <Dictionary <string, object> >(jsonStr);
                if (dic.Count < 2)
                {
                    throw new ArgumentNullException(dic["error"].ToString());
                }
                msgCount = Convert.ToString(dic["alertcount"]);
                ArrayList list = dic["locatlist"] as ArrayList;

                DateTime       connectTime;
                double         lat, lng;
                Entity.Devices device;

                for (int i = 0; i < list.Count; i++)
                {
                    device      = new Entity.Devices();
                    dic         = list[i] as Dictionary <string, object>;
                    lat         = 0; lng = 0;
                    connectTime = Convert.ToDateTime(dic["connecttime"]);
                    if (!string.IsNullOrWhiteSpace(dic["lbs"].toStringEmpty()))
                    {
                        Dictionary <string, object> lbs = (Dictionary <string, object>)dic["lbs"];
                        if (lbs["time"].toStringEmpty().toDateTime() > connectTime)
                        {
                            dic["lat"] = lbs["lat"]; dic["lon"] = lbs["lon"];
                        }
                        else if (Convert.ToDouble(dic["lat"]) == 0.00 || Convert.ToDouble(dic["lon"]) == 0.00)
                        {
                            dic["lat"] = lbs["lat"]; dic["lon"] = lbs["lon"];
                        }
                        device.ConnectTime = lbs["time"].toStringEmpty().toDateTime().AddHours(8).ToString();
                    }
                    Gps g = EvilTransform.PositionUtil.gcj02_To_Bd09(Convert.ToDouble(dic["lat"]), Convert.ToDouble(dic["lon"]));
                    lat        = g.getWgLat();
                    lng        = g.getWgLon();
                    device.Lat = lat + ""; device.Lon = lng + "";

                    device.ConnectTime = connectTime.ToString("yyyy-MM-dd HH:mm:ss");
                    device.Id          = Convert.ToString(dic["id"]);
                    device.Name        = Convert.ToString(dic["name"]);
                    device.EndTime     = Convert.ToString(dic["endtime"]); device.DeviceTime = Convert.ToString(dic["devicetime"]);
                    device.Direction   = Convert.ToString(dic["direction"]);
                    device.Speed       = Convert.ToString(dic["speed"]); device.Status = Convert.ToString(dic["status"]);
                    device.OnLine      = !((DateTime.Now - connectTime).TotalMinutes > Utils.OffLineMinute);

                    if (connectTime < Convert.ToDateTime("0010-01-01"))
                    {
                        device.DeviceStatus = (int)DeviceStatus.未激活 + "," + device.Speed;
                    }
                    else if ((DateTime.Now - connectTime).TotalMinutes > Utils.OffLineMinute)
                    {
                        device.DeviceStatus = (int)DeviceStatus.离线 + "," + Convert.ToInt32((DateTime.Now - connectTime).TotalMinutes);
                    }
                    else if (Convert.ToInt32(device.Speed) > 0)
                    {
                        device.DeviceStatus = (int)DeviceStatus.行驶 + "," + Convert.ToDouble(device.Speed) + "km";
                    }
                    else if (Convert.ToInt32(device.Speed) <= 0 && (DateTime.Now - connectTime).TotalMinutes <= Utils.OffLineMinute)
                    {
                        device.DeviceStatus = (int)DeviceStatus.停止 + "," + (DateTime.Now - Convert.ToDateTime(connectTime)).TotalMinutes;
                    }
                    deviceList.Add(device);
                }
                return(deviceList);
            }
            catch (Exception ex)
            {
                Utils.log("GetDevicesByUserID_Bll方法出错:" + ex.Message + ", 堆栈信息:" + ex.StackTrace);
                return(deviceList);
            }
        }