GOOGLE衛星地圖 計算方式

 

 

 

摘自 http://www.cnblogs.com/Tangf/archive/2006/07/23/457902.html 

 

寫的重名了,Pany的原文:http://panyee.cnblogs.com/archive/2006/04/27/386914.html
只是用了下覺得算法不太對。
後來又找了下以前收集的在南京大學小百合BBS上的資料,找到了些有用的東西,摘錄一些有用的文字:
Google衛星地圖是由256x256大小的jpeg圖片拼接而成,每塊圖片的URL格式爲“http://kh.google.com/kh?v=2&t=trstrqqstsrqttsttq”樣。參數v與圖片關係不大,主要是參數t起作用,它是“qrst”4個字符排列而成的字符串。爲獲取某經緯度的URL,就需要把經緯度轉化爲“qrst”字符串。 Google衛星地圖在zoom=1時,全球就爲一個256x256的圖片,它的中心經緯度爲(0,0),URL爲“http://kh.google.com/kh?v=2&t=t”。zoom=2時裂化爲4塊,每塊的編號爲:左上”t=tq”,右上”t=tr”,右下“t=ts”,左下”t=tt”。依此類推,每放大一倍,每一小塊都裂分爲四,從左上到右下順時針按qrst編號,裂分後的編碼爲裂分前的編號上小塊的編號。
摘錄一個網頁:http://intepid.com/stuff/gmkh/,在這個網頁上輸入一個座標和縮放級別就可以顯示地圖,並顯示從世界圖到詳細圖的逐層計算。
摘錄兩個代碼,一個是上面這個網頁中的JS代碼,一個是小百合論壇上說的另一中Delphi的算法。

原文連接:
I was born at TSRRTRSQSQQQRQRTSS
有人知道google earth嗎-小百合論壇

延伸:通過這樣的算法可以看出Google切圖的索引方式,那麼能否推算出地圖切割算法呢?

兩個代碼如下

Gmap URL_JS
function GetQuadtreeAddress(long, lat)
{
var PI = 3.1415926535897;
var digits = 18; // how many digits precision
// now convert to normalized square coordinates
// use standard equations to map into mercator projection
var x = (180.0 + parseFloat(long)) / 360.0;
var y = -parseFloat(lat) * PI / 180; // convert to radians
y = 0.5 * Math.log((1+Math.sin(y)) / (1 - Math.sin(y)));
y *= 1.0/(2 * PI); // scale factor from radians to normalized
y += 0.5; // and make y range from 0 - 1
var quad = "t"; // google addresses start with t
var lookup = "qrts"; // tl tr bl br
while (digits–)
{
// make sure we only look at fractional part
x -= Math.floor(x);
y -= Math.floor(y);
quad = quad + lookup.substr((x >= 0.5 ? 1 : 0) + (y >= 0.5 ? 2 : 0), 1);
// now descend into that square
x *= 2;
y *= 2;
}
return quad;
}

=================

function getSatURL(zoom: integer; X, Y: double): string;
var
  wx, wy, cx, cy: double;
  tid: string;
  i: integer;
begin
  cx := 0;
  cy := 0;
  wx := 180;
  wy := 180;
  tid := 't';

  for i := 1 to zoom-1 do
  begin
    if (x >= cx) and (y >= cy) then
    begin
      tid := tid + 'r';
      cx := cx + wx / 2;
      cy := cy + wy / 2;
    end
    else if (x >= cx) and (y < cy) then
    begin
      tid := tid + 's';
      cx := cx + wx / 2;
      cy := cy - wy / 2;
    end
    else if (x < cx) and (y < cy) then
    begin
      tid := tid + 't';
      cx := cx - wx / 2;
      cy := cy - wy / 2;
    end
    else
    begin
      tid := tid + 'q';
      cx := cx - wx / 2;
      cy := cy + wy / 2;
    end;
    wx := wx / 2;
    wy := wy / 2;
  end;
  result := 'http://kh.google.com/kh?v=2&t=' + tid;
end;

發佈了333 篇原創文章 · 獲贊 14 · 訪問量 73萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章