Ejemplo n.º 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("未知.");
            }
        }
Ejemplo n.º 2
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>());
            }
        }