C# 处理 google map 经纬度偏移量

本文介绍了一个用于处理地理位置坐标转换的类LocationLogic,该类提供了一种机制来获取并转换地理坐标,包括经度和纬度的数据。通过调用特定的方法和服务,能够实现从原始坐标到目标坐标的精确转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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) { throw ex; } return LatLng; } } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值