/// <summary> /// 获取当位置的经纬度 /// </summary> /// <returns></returns> static public String GetCurrentLocation() { string result = string.Empty; try { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(); watcher.Start(); watcher.TryStart(false, TimeSpan.FromMilliseconds(60000));////超过5S则返回False; GeoCoordinate coord = watcher.Position.Location; if (coord.IsUnknown != true) { result = "东经:" + coord.Longitude.ToString() + "\t北纬" + coord.Latitude.ToString() + "\n"; } else { result = "地理未知"; } } catch (Exception ex) { ExceptionLogBLL.WriteExceptionLogToDB(ex.ToString()); result = "地理未知" + ex.Message; } return(result); }
/// <summary> /// 百度IP定位当前位置信息 /// </summary> /// <returns></returns> static public String GetLocationInfo() { try { string Ak = CommonHelper.GetAppSettingsValue("Ak", "TBHTGEjDi6X1MRIthT3TLFvo5Zy07IhK"); string baiduIpApi = CommonHelper.GetAppSettingsValue("baiduIpApi", "http://api.map.baidu.com/location/ip"); string url = string.Format("{1}?ak={0}&coor=bd09ll", Ak, baiduIpApi); string retrunStr = UtilityHelper.HttpService.GetHttpWebResponseByRestSharp(url, string.Empty); return(retrunStr); } catch (Exception ex) { ExceptionLogBLL.WriteExceptionLogToDB(ex.ToString()); return(null); } }
/// <summary> /// 地址解析 /// </summary> /// <param name="address">要定位的地址</param> /// <returns>返回位置信息json</returns> static public String GetLocationByAddress(string address) { try { string Ak = CommonHelper.GetAppSettingsValue("Ak", "TBHTGEjDi6X1MRIthT3TLFvo5Zy07IhK"); string baiduLocationApi = CommonHelper.GetAppSettingsValue("baiduLocationApi", "http://api.map.baidu.com/geocoder/v2/"); string url = string.Format("{2}?address={0}&output=json&ak={1}&callback=showLocation", address, Ak, baiduLocationApi); string retrunStr = UtilityHelper.HttpService.GetHttpWebResponseByRestSharp(url, string.Empty); return(retrunStr); } catch (Exception ex) { ExceptionLogBLL.WriteExceptionLogToDB(ex.ToString()); return(null); } }
/// <summary> /// 逆地址解析 /// </summary> /// <param name="longitude">经度</param> /// <param name="latitude">纬度</param> /// <param name="output">输出格式为json或者xml</param> /// <param name="pois">是否显示指定位置周边的poi,0为不显示,1为显示。当值为1时,默认显示周边1000米内的poi。</param> /// <returns>json或者xml</returns> static public String GetAddressByLocation(string longitude, string latitude, string output, int pois = 0) { try { string Ak = CommonHelper.GetAppSettingsValue("Ak", "TBHTGEjDi6X1MRIthT3TLFvo5Zy07IhK"); string baiduLocationApi = CommonHelper.GetAppSettingsValue("baiduLocationApi", "http://api.map.baidu.com/geocoder/v2/"); string url = string.Format("{5}?callback=renderReverse&location={0},{1}&output={2}&pois={3}&ak={4}" , latitude, longitude, output, pois, Ak, baiduLocationApi); string retrunStr = UtilityHelper.HttpService.GetHttpWebResponseByRestSharp(url, string.Empty); //string temp1 = UtilityHelper.Utils.UnicodeToString(retrunStr); return(retrunStr); } catch (Exception ex) { ExceptionLogBLL.WriteExceptionLogToDB(ex.ToString()); return(null); } }
/// <summary> /// 记录日志到数据库 /// </summary> public static void WriteExceptionLogToDB(string msg) { try { StackTrace st = new StackTrace(true); MethodBase mb = st.GetFrame(1).GetMethod(); string clsString = mb.DeclaringType.FullName; string mName = mb.Name; ExceptionLog entity = new ExceptionLog(); entity.ClassName = clsString; entity.MethodName = mName; entity.ErrorDesc = msg; entity.RecordIsDelete = false; entity.RecordCreateTime = DateTime.Now; entity.RecordUpdateTime = DateTime.Now; ExceptionLogBLL op = new ExceptionLogBLL(); op.AddExceptionLog(entity); } catch { } }