Google 维度转瓦片url

private int z1 = 0, z2 = 13;     private int Left_LONG = 115, Right_LONG = 125;     private int Top_LAT = 31, Botton_LAT = 29;     private string url = "http://mt3.google.cn/vt/lyrs=m@174000000&hl=zh-CN&gl=cn&src=app&x={0}&y={1}&z={2}&s=Ga";     string filepath = @"F:\";       protected void Page_Load(object sender, EventArgs e)     {         for (int z = this.z1; z <= this.z2; z++)         {             int outLong1 = 0, outLat1 = 0;             this.CalTileXY(z, this.Left_LONG, this.Top_LAT, out outLong1, out outLat1);             int outLong2 = 0, outLat2 = 0;             this.CalTileXY(z, this.Right_LONG, this.Botton_LAT, out outLong2, out outLat2);

            for (int i = outLong1; i <= outLong2; i++)             {                 for (int j = outLat1; j <= outLat2; j++)                 {                     string urlPath = string.Format(this.url, i, j, z);                     System.Net.WebClient myWebClient = new System.Net.WebClient();                     myWebClient.DownloadFile(urlPath, filepath + "cn_3356_1676_12.png");                     this.Response.Write(urlPath + "</br>");                 }             }         }

    }

    /// <summary>     /// 经纬度,转换成瓦片x,y     /// </summary>     public void CalTileXY(int z, double lng, double lat, out int outLONG, out int outLAT)     {         outLONG = 0;         outLAT = 0;

        double x = (180 + lng) / 360;         double y = -lat * Math.PI / 180;         y= 0.5 * Math.Log((1+Math.Sin(y)) / (1-Math.Sin(y)));         y*= 1.0/(2*Math.PI);         y+=0.5;         outLONG = Convert.ToInt32(x * (1 << z));         outLAT = Convert.ToInt32(y * (1 << z));     }

posted @ 2012-04-25 18:25  顺手  阅读(216)  评论(0)    收藏  举报