Google、Soso、Baidu卫星图url研究

前一段时间因为公司有个项目需要我研究一下Google的卫星图的地址规律,开始我以为会很艰难认为Google那么大公司url应该会加密什么的,结果发现Google和Soso、Baidu、Sogou这几个比较起来Google的url演算是最简单且明了的,废话不说了。

打开Google Map我们可以看到一张地图,将它放大或者缩小就可以看到不同的地图(很多张的图片)。url像这样:http://khm1.google.com/kh/v=125&src=app&x=0&y=0&z=0   (红色部分均为可变的参数)

Google的作法是世界的第0层(z=0)就是一张图构成:

z=1的效果就是将它切分为4份见下图:

依次类推,我们可以得到一个公式:NUM=2^(N+1)

NUM:x或者y方向上的图片数

N:第几层z轴

然后引入Mercator库(我自己写的麦卡拓转换)code:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Windows;
 6 
 7 namespace MapsDownloader
 8 {
 9     class Mercator
10     {
11         private double NormalToMercator(double y)
12         {
13             y -= 0.5;
14             y *= 2.0 * Math.PI;
15             y = Math.Exp(y * 2.0);
16             y = (y - 1) / (y + 1.0);
17             y = Math.Asin(y);
18             y = y * -180.0 / Math.PI;
19             return y;
20         }
21         private double MercatorToNormal(double y)
22         {
23             y = -y * Math.PI / 180.0;
24             y = Math.Sin(y);
25             y = (1.0 + y) / (1.0 - y);
26             y = 0.5 * Math.Log(y);
27             y *= 1.0 / (2.0 * Math.PI);
28             y += 0.5;
29             return y;
30         }
31         private double getNormailByY(double y,int picnum)
32         {
33             return y/picnum;
34         }
35         private double getYByNormail(double y, int picnum)
36         {
37             return picnum * y;
38         }
39         ///
40         ///传入:-26.851029008675013 返回:-26° 51' 3" 
41         public string GetSexagesimalNotation(double x)
42         {
43             //to string format: 23° 27′ 30"
44             var ret = "";
45             if (x < 0)
46             {
47                 ret += '-';
48                 x = -x;
49             }
50             ret += Math.Floor(x);
51             ret += "° ";
52     
53             x = (x - Math.Floor(x)) * 60;
54             ret += Math.Floor(x);
55             ret += "' ";
56     
57             x = (x - Math.Floor(x)) * 60;
58             ret += Math.Floor(x);
59             ret += "\" ";
60 
61             return ret;
62         }
63         public Point Google_XYZ_to_LatLng(int x, int y, int z)     //lat [0]  , lng [1]
64         {
65             Point LatLng = new Point();
66             int picnum = 2 << (z - 1);   //z层在x、y轴上存在多少张
67             double onex = 360.0 / picnum;    //平均每一张占用多少经纬度
68             double xlat = onex * x;
69             if (xlat > 360.0)       //如果超过360就剪掉它
70                 xlat = xlat % 360.0;
71             if (xlat > 180.0)
72                 LatLng.X = onex * x - 180.0;
73             else
74                 LatLng.X = -(180.0 - onex * x);
75             LatLng.Y = NormalToMercator(getNormailByY(y, picnum));
76             return LatLng;
77         }
78         public Point Google_LatLngZ_to_XY(double Lat, double Lng, int z)       //return x,y array
79         {
80             Point xy = new Point();
81             int picnum = 2 << (z - 1);   //z层在x、y轴上存在多少张
82 double onex = 360.0 / picnum; ////平均每一张占用多少经纬度
83 Lat += 180.0;
84 xy.X = Convert.ToInt32(Lat / onex); //x
85 xy.Y = Convert.ToInt32(getYByNormail(MercatorToNormal(Lng), picnum)); //y
86 return xy;
87 }
88 }
89 }

主要是Y轴方向转换麻烦需要用到这些函数,因为Mercator当初设计的缺陷就是越往两极地区越不准确。

下面两个函数Google_XYZ_to_LatLng、Google_LatLngZ_to_XY提供了将XYZ转换成为 经纬度,和经纬度转换成Google的XYZ轴,有了这些基础我们就可以用html和JQuery写出一个简易的GoogleMap 网页键盘版本:

  1 
  2 
  3 
  4 
  5 Keyboard Google Map——By MaxHo
  6 
  7 
278 
279 
280 
281 x: 282 y: 283 z: 284     285 291 使用鍵盤熱鍵上下左右鍵調節方向,E、Q控制地圖縮放 292 293 294 295 296 297 298
299 左上角經緯度:   300 301302303304305306307308309310311312313314315316317318319320321322
323 324

soso map和baidu map的地图url规律就蛋疼许多,因为他们的Y轴非要与google的方向相反。。没法,为了适应他们单独写了函数

这还不算什么,soso还单独弄出来一个参数dx、dy,后来我还是自己看sosomap中的已经被搅乱的js代码才分析出来只是由x和y通过Math.floor(x/16)运算得到的,腾讯这样搞这有木有意义@@ ,为了后台省资源?

百度也是跟着腾讯一样把地图的Y轴弄反,不过没有dx、dy,不过他们我实测都有经过偏移模组的偏移。也就是说你给定一个经纬度通过标准的麦卡拓算出来的xyz总有一点点几百米的偏移。这些倒是怪不到他。更变态的是sogoumap完全没有办法猜清楚是什么规律,我直接选择放弃了,都不想看它的js代码了,还是洗洗睡吧。

转载于:https://www.cnblogs.com/hyb1/archive/2013/04/25/3042423.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部