GOOGLE卫星地图URL中的Tile位置编码算法

GOOLE卫星地图(GE)是我常玩的一个工具,深深为其魅力所吸引,后来在网上搜索有关GE卫星地图图片的一些文章,发现的其调用的URL格式为:http://kh0.google.com/kh?n=404&v=8&t=trtqtt,其中t参数编码了图像的位置,t长度表明zoom的级别。 要想看到全球,设置t为t;下一显示级别,Tile被分成4个象限,顺时针依次是:q,r,s和t;要想看哪个象限,就把这个字符附到t的后面就可以了。例如:t=tq,代表左上的象限,依次类推,q,r,s和t可用下图来表示其意义:

其Tile位置编码算法如下:
FUNCTION getGMurl(uZoom as Integer,lat as Integer,lon as Integer)
PI = 3.1415926535897
x=(180.0 + lon)/360.0
y=-(lat)*PI/180
y=0.5*log((1+sin(y))/(1-sin(y)))
y =y*1.0/(2*PI)
y =y+ 0.5
tid="t"
lookup="qrts"
FOR i=uZoom TO 1 STEP -1
x =x-floor(x)
y =y-floor(y)
quad=quad+substr(lookup,IIF(x>=0.5,2,1)+iif(y>=0.5,2,0),1)
x=x*2
y=y*2
endf
RETURN 'http://kh0.google.com/kh?n=404&v='+ALLTRIM(STR(uZoom))+'&t=t'+tid
ENDFUNC

这个算法也可以变形为如下写法:
FUNCTION getGEurl(uZoom as Integer,lat as Integer,lon as Integer)
*参数:uZoom-放大倍数,lal-纬度4,lon-经度
*注意:uZoom值一般在1-18之间,但不一定能达到18倍,甚至更低的倍数。
*返回值:GE地图的图片地址,字符型。
STORE 0xB4 TO wx,wy
STORE 0x00 TO cx,cy
tid=''
FOR i=1 TO uZoom-1
DO CASE
   CASE (lat>=cx) and (lon>=cy)
         tid=tid+'r'
         cx=cx+wx/2
         cy=cy+wy/2
   CASE (lat>=cx) and (lon<cy)
         tid=tid+'s'
         cx=cx+wx/2
         cy=cy-wy/2
   CASE (lat<cx) and (lon<cy)
        tid=tid+'t'
        cx=cx-wx/2
        cy=cy-wy/2
   OTHER
        tid=tid+'q'
        cx=cx-wx/2
        cy=cy+wy/2
ENDC
wx=wx/2
wy=wy/2
ENDF
RETURN 'http://kh0.google.com/kh?n=404&v='+ALLT(STR(uZoom))+'&t=t'+tid
ENDFUNC

如要获得温州(34.262812,108.963207)的10倍卫星图的URL:
getGEurl(10,34.262812,108.963207)
结算结果为:http://kh3.google.com/kh?n=404&v=3&t=trstqrsts
效果如下:

这个算法是理论上的, 每个Tile是256×256的JPG或者PNG图片,如上图。 Google采用4个服务器平衡负载,它们是kh0, kh1, kh2 和 kh3。
Google 地图使用了一个保护机制,以保证服务器的质量。如果一个IP的请求次数过多,它会被加到黑名单,并提示一个很友好的消息:
We're sorry... ... but yourquery looks similar to automated requests from a computer virus orspyware application. To protect our users, we can't process yourrequest right now. We'll restore your access as quickly as possible, sotry again soon. In the meantime, if you suspect that your computer ornetwork has been infected, you might want to run a virus checker orspyware remover to make sure that your systems are free of viruses andother spurious software. We apologize for the inconvenience, and hopewe'll see you again on Google.
呵呵,IP倍禁了!

 


通过截取GE的数据后发现,后来发现还有很多可以获取更清晰卫星图片的途径,继续研究,呵呵!
posted @ 2011-12-27 10:51  zhh  阅读(1474)  评论(0编辑  收藏  举报