close

decimal[] LatLng = new decimal[] { lat, lng };

 

int OX = 0;
int OY = 0;

我們首先要解決兩個問題,一個是偏移量數据的問題,二是計算實際應該顯示經緯度的算法

LatLng[0] = Convert.ToDecimal(Map.PixelYToLat(PY1, 18));
LatLng[1] = Convert.ToDecimal(Map.PixelXToLng(PX1, 18));
}
}
catch (Exception ex)
{
ExceptionHandler.ExceptionProcess(ex);
}

return LatLng;
}

if (CacheManager.Get(Lat + “_” + Lng) != null)
{
oXY = CacheManager.Get(Lat + “_” + Lng).ToString();
}

在上表中,我們存的都是18級的偏移量數据,而我們在存經緯度的時候精確到0.01, 例如,我們的經緯度是 52.12123213, 120.6123123, 我們會取 52.12,120.61 的偏移量去計算偏移後的經緯度。
源碼如下:

1. 如何獲得偏移量數据。
Google 已經有一個偏移糾正的API,如 http://ditu.google.cn/maps/vp?spn=0.0,0.0&z=18&vp=39.111195,117.148067,通過這個API,返回的是 以下的格式:

string oXY = “”;
string Lat = lat.ToString().Substring(0, lat.ToString().IndexOf(‘.’) + 3);
string Lng = lng.ToString().Substring(0, lng.ToString().IndexOf(‘.’) + 3);

if (OX != 0 && OY != 0)
{
Map.LatLongToPixelXY(Convert.ToDouble(lat), Convert.ToDouble(lng), 18, out PX, out PY);

53.12120.611321-46153.12120.621322-46253.12120.631324-46553.12120.641327-46853.12120.651331-47353.12120.661336-478

public decimal[] GetLatLng(decimal lat, decimal lng)
{
int PX, PY;

int PX1, PY1;

oXY = OX.ToString() + “,” + OY.ToString();
CacheManager.Permanent(Lat + “_” + Lng, oXY);
}
}

PX1 = PX + OX;
PY1 = PY + OY;

try
{
Database db = DatabaseFactory.CreateDatabase();
string sqlCmd = “SELECT TOP 1 X,Y FROM Offset WHERE Lat=” + Lat + ” AND Lng=” + Lng;
DbCommand dbCmd = db.GetSqlStringCommand(sqlCmd);
using (IDataReader dr = db.ExecuteReader(dbCmd))
{
if (dr.Read())
{
OX = DataReaderHelper.GetInt32(dr, “X”);
OY = DataReaderHelper.GetInt32(dr, “Y”);

在Google 地圖中國部分,平面地圖和衛星圖都存則偏移量,而這個偏移量不是線性的,我們在做GPS定位平台的時候,在播放歷史軌跡的時候往往發現車輛行駛的路線偏離了地圖上的實際道路,這點是很多客戶不能接受的,如何解決這個問題呢。

39.111195, 117.148067, 18, [9, -2, 18, -4, 37, -8, 74, -16, 149, -33, 298, -67, 596, -135, 1193, -270]
以上的數据的含義是僟個放大級別的偏移量:
18級: 1193, -270
17級: 596, -135
16級: 298, -67
15級: 149, -33
14級: 74, -16
13級: 37, -8
12級: 18, -4
11級: 9, -2


一般情況來說,我們為了得到比較高的精度度,會取 18級別的數据1193,-270,1193為x方向上精度的偏移像素,-270為y方向上維度偏移像素。


由這個數据計算39.111195,117.148067在偏移之後的經緯度為39.11231854918217,117,LV N41542 Sistina 小號手袋 手提包 老花系列 LV包包價格、目錄、型錄、新款 官方網站旗艦店.15446412563324,具體的算法源碼如下:


2. 算法和源碼
首先,我們會建一個表Offset,這個表會存所有經緯度偏移量的數据,格式如下:

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 weirmxzx 的頭像
    weirmxzx

    阿貍

    weirmxzx 發表在 痞客邦 留言(0) 人氣()