示例#1
0
        public Dictionary <string, string> GetMessageInfoByID(string eid)
        {
            try
            {
                SQLServerOperating          s      = new SQLServerOperating();
                string                      strSql = @"select CASE when d.devicename='' then d.SerialNumber else d.DeviceName end DeviceName,dateadd(HH,8, em.created) Created,em.OLat,em.OLng ,
                                case when geo.FenceName is null then em.Message else em.Message+':'+geo.FenceName end Message
                                from ExceptionMessage em inner join Devices d on d.DeviceID=em.DeviceID 
                                left join GeoFence geo on geo.GeofenceID=em.GeoFenceID 
                                where ExceptionID=@ExceptionID";
                DataTable                   table  = s.Selects(strSql, new SqlParameter[] { new SqlParameter("ExceptionID", eid) });
                Dictionary <string, string> dic    = new Dictionary <string, string>();

                Geocoding geo = GetCurrentMapType();
                foreach (DataRow row in table.Rows)
                {
                    foreach (DataColumn dc in table.Columns)
                    {
                        dic[dc.ColumnName] = row[dc.ColumnName].toStringEmpty();
                    }
                }
                Mgoo.Position.IGeocoding geocoding = null;
                if (geo.GetType().Name.ToLower() == "baidu")
                {
                    geocoding = new Mgoo.Position.Geocod.Baidu();
                }
                else if (geo.GetType().Name.ToLower() == "amap")
                {
                    geocoding = new Mgoo.Position.Geocod.Amap();
                }
                else
                {
                    geocoding = new Mgoo.Position.Geocod.Google();
                }
                var point = geocoding.Translate(dic["OLat"].toDouble(), dic["OLng"].toDouble());
                var task  = Task.Run(() => {
                    return(geocoding.GetAddress(point));
                });
                dic["OLat"]    = point.Lat.ToString();
                dic["OLng"]    = point.Lng.ToString();
                dic["Address"] = task.Result;
                return(dic);
            }
            catch (Exception ex)
            {
                Utils.log("Message>GetMessageInfoByID ERROR:" + ex.Message);
                return(new Dictionary <string, string>());
            }
        }
示例#2
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("未知.");
            }
        }
示例#3
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);
            }
        }