コード例 #1
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);
            }
コード例 #2
0
        public Gps Translate(string lat, string lng, bool address = true)
        {
            double _lat = lat.toDouble();
            double _lng = lng.toDouble();
            Gps    gps;

            if (_lat == -1.0 && _lng == -1.0)
            {
                gps         = new Gps(-1.000, -1.000);
                gps.Address = "未解析到地址.";
                return(gps);
            }
            if (string.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lng))
            {
                gps         = new Gps(-1.000, -1.000);
                gps.Address = "未解析到地址.";
                return(gps);
            }
            gps = EvilTransform.PositionUtil.gps84_To_Gcj02(_lat, _lng);
            try
            {
                if (address)
                {
                    gps.Address = GetAddress(gps);
                }
                return(gps);
            }
            catch (Exception ex)
            {
                gps.Address = "未知";
                Utils.log("获取地址异常(Baidu translate):" + ex.Message);
                return(gps);
            }
        }
コード例 #3
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("未知.");
            }
        }
コード例 #4
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;
     }
 }
コード例 #5
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));
            }
コード例 #6
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;
            }
        }
コード例 #7
0
            /// <summary>
            ///  将  gps84 坐标转换成 BD-09 坐标
            /// </summary>
            /// <returns></returns>
            public static Gps gps84_To_Bd09(double lat, double lon)
            {
                double π = pi * 3000 / 180;
                double x = lon, y = lat;
                double z     = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * π);
                double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * π);
                Gps    bd09  = transform(z * Math.Sin(theta) + 0.006, z * Math.Cos(theta) + 0.0065);

                return(bd09);
            }
コード例 #8
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);
        }
コード例 #9
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("未知.");
            }
        }
コード例 #10
0
        /// <summary>
        /// 利用高德地图API把gps84坐标系转换成gcj02坐标系
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        //public static Gps amap_gps84toGcj02(string lat, string lng, bool address = true)
        //{
        //    Gps gps = null;
        //    if (string.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lng))
        //    {
        //        gps = new Gps(-1,-1);
        //        return gps;
        //    }
        //    MG_DAL.MgoogpsWebClient mwc = new MG_DAL.MgoogpsWebClient();
        //    string key = ConfigurationManager.AppSettings["GaoDeKey"].toStringEmpty();
        //    mwc.RequestUrl = "http://restapi.amap.com/v3/assistant/coordinate/convert?key="+ key + "&locations=" + lng + "," + lat + "&coordsys=gps";
        //    mwc.RequestMethodType = "GET";
        //    //{"status":"1","info":"ok","infocode":"10000","locations":"116.487586,39.991755"}
        //    string json = mwc.RequestSend();
        //    Dictionary<string, string> dic = Utils.ToDictionary(json);
        //    string[] locations = dic["locations"].toStringEmpty().Split(',');
        //      gps = new Gps(Convert.ToDouble(locations[1]), Convert.ToDouble(locations[0]));
        //    if (address)
        //    {
        //        gps.Address = GetAddress(gps.getWgLat(), gps.getWgLon(), key);
        //    }
        //    return gps;
        //}
        /// <summary>
        /// 根据本地算法把gps84坐标系转换成gcj02(高德)坐标系
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        public static Gps gps84_To_Gcj02(string lat, string lng, string key = null, bool address = true)
        {
            double _lat = lat.toDouble();
            double _lng = lng.toDouble();

            if (key == null)
            {
                key = ConfigurationManager.AppSettings["AmapKey"].ToString();
            }
            Gps gps;

            if (string.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lng) || _lat == -1.0 || _lng == -1.0)
            {
                gps         = new Gps(-1.000, -1.000);
                gps.Address = "未解析到地址.";
                return(gps);
            }
            gps = MG_BLL.EvilTransform.PositionUtil.gps84_To_Gcj02(lat.toDouble(), lng.toDouble());
            try
            {
                if (address)
                {
                    Mgoo.Position.IGeocoding geocoding = new Mgoo.Position.Geocod.Amap();
                    gps.Address = geocoding.GetAddress(new Mgoo.Position.Point(gps.getWgLat(), gps.getWgLon()));
                    // Geocoding geo = new Amap();
                    //geo.key = key;
                    // gps.Address = geo.GetAddress(gps);
                }
                return(gps);
            }
            catch (Exception ex)
            {
                gps.Address = "未知";
                Utils.log("获取地址异常(gps84_To_Gcj02):" + ex.Message);
                return(gps);
            }
        }
コード例 #11
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);
            }
        }