Google卫星地图的URL计算

写的重名了,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切图的索引方式,那么能否推算出地图切割算法呢?

两个代码如下

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

InBlock.gif
return quad;
ExpandedBlockEnd.gif}

ContractedBlock.gif ExpandedBlockStart.gif Gmap URL_Delphi
None.giffunction getSatURL(zoom: integer; X, Y: double): string;
None.gifvar
None.gif  wx, wy, cx, cy: 
double;
None.gif  tid: 
string;
None.gif  i: integer;
None.gifbegin
None.gif  cx :
= 0;
None.gif  cy :
= 0;
None.gif  wx :
= 180;
None.gif  wy :
= 180;
None.gif  tid :
= 't';
None.gif
None.gif  
for i := 1 to zoom-1 do
None.gif  begin
None.gif    
if (x >= cx) and (y >= cy) then
None.gif    begin
None.gif      tid :
= tid + 'r';
None.gif      cx :
= cx + wx / 2;
None.gif      cy :
= cy + wy / 2;
None.gif    end
None.gif    
else if (x >= cx) and (y < cy) then
None.gif    begin
None.gif      tid :
= tid + 's';
None.gif      cx :
= cx + wx / 2;
None.gif      cy :
= cy - wy / 2;
None.gif    end
None.gif    
else if (x < cx) and (y < cy) then
None.gif    begin
None.gif      tid :
= tid + 't';
None.gif      cx :
= cx - wx / 2;
None.gif      cy :
= cy - wy / 2;
None.gif    end
None.gif    
else
None.gif    begin
None.gif      tid :
= tid + 'q';
None.gif      cx :
= cx - wx / 2;
None.gif      cy :
= cy + wy / 2;
None.gif    end;
None.gif    wx :
= wx / 2;
None.gif    wy :
= wy / 2;
None.gif  end;
None.gif  result :
= 'http://kh.google.com/kh?v=2&t=' + tid;
None.gifend;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值