日期:2014-05-18 浏览次数:20922 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; namespace WSGPSGateway.BLL { public class LocationLogic { public LocationLogic() { } private static volatile LocationLogic _LocationLogic = new LocationLogic(); /// <summary> /// 得到实例 /// </summary> /// <returns></returns> public static LocationLogic GetInstance() { if (_LocationLogic == null) { lock (typeof(LocationLogic)) { if (_LocationLogic == null) { _LocationLogic = new LocationLogic(); } } } return _LocationLogic; } /// <summary> /// 得到经度和纬度 /// </summary> /// <param name="lat"></param> /// <param name="lng"></param> /// <returns></returns> public decimal[] GetLatLng(decimal lat, decimal lng) { int PX, PY; decimal? PX1, PY1; decimal? OX; decimal? OY; decimal[] LatLng = new decimal[] { lat, lng }; //传入两个参数 ,经度和纬度 ,然后返回经过解析的经度和纬度 try { DAL.DeviceinfoDataSetTableAdapters.deviceinfoAdapter da = new DAL.DeviceinfoDataSetTableAdapters.deviceinfoAdapter(); da.P_GETLATLNG(lat, lng, out OX, out OY); OX = Convert.ToDecimal(OX); OY = Convert.ToDecimal(OY); if (OX != 0 && OY != 0) { Map.LatLongToPixelXY(Convert.ToDouble(lat), Convert.ToDouble(lng), 18, out PX, out PY); PX1 = PX + OX; PY1 = PY + OY; LatLng[0] = Convert.ToDecimal(Map.PixelYToLat(Convert.ToDouble(PY1), 18)); LatLng[1] = Convert.ToDecimal(Map.PixelXToLng(Convert.ToDouble(PX1), 18)); } } catch (Exception ex) { DAL.Log.Write(ex); } return LatLng; } } }