//
// Google Map Tiles Downloader in C# by coolypf
// No rights reserved, neither warranty nor guarantee
// using System;
using System.Collections.Generic;
using System.Drawing;
using System.Net; namespace GMapsDownloader
{
class Program
{
const double EarthRadius = ;
const double MinLatitude = -85.05112878;
const double MaxLatitude = 85.05112878;
const double MinLongitude = -;
const double MaxLongitude = ; const string NameFormat = "{0}-{1}-{2}.png";
const string TileSource = "https://mts{0}.google.com/vt/lyrs=m@207000000&hl=zh-CN&gl=CN&src=app&x={1}&y={2}&z={3}&s={4}";
const string SourceTail = "Galileo"; static Random rng = new Random(); static double Clip(double n, double minValue, double maxValue)
{
return Math.Min(Math.Max(n, minValue), maxValue);
} static void LatLongToTileXY(double latitude, double longitude, int levelOfDetail, out int tileX, out int tileY)
{
double x = (longitude + ) / ;
double sinLatitude = Math.Sin(latitude * Math.PI / );
double y = 0.5 - Math.Log(( + sinLatitude) / ( - sinLatitude)) / ( * Math.PI); uint mapSize = 1u << levelOfDetail;
tileX = (int)Clip(x * mapSize + 0.5, , mapSize - );
tileY = (int)Clip(y * mapSize + 0.5, , mapSize - );
} static bool Validate(int x, int y, int l)
{
bool ret = false;
try
{
Bitmap bmp = new Bitmap(string.Format(NameFormat, x, y, l));
ret = (bmp.Height == && bmp.Width == );
bmp.Dispose();
}
catch (Exception) { }
return ret;
} static void Download(int x, int y, int l)
{
try
{
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:21.0) Gecko/20130109 Firefox/21.0");
string loc = string.Format(TileSource, rng.Next(), x, y, l,
SourceTail.Substring(, rng.Next(SourceTail.Length)));
string name = string.Format(NameFormat, x, y, l);
client.DownloadFile(loc, name);
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine(ex.Message);
}
} static void Main(string[] args)
{
try
{
Console.WriteLine("Google Map Tiles Downloader");
Console.WriteLine("lat1, long1 lat2, long2 level");
double[] array = new double[];
int level = , i = ;
string[] splits = Console.ReadLine().Split(' ', ',');
foreach (string s in splits)
{
if (s.Trim() == "")
continue;
if (i < ) array[i++] = double.Parse(s);
else level = int.Parse(s);
}
double lat1 = Clip(array[], MinLatitude, MaxLatitude);
double lat2 = Clip(array[], MinLatitude, MaxLatitude);
double long1 = Clip(array[], MinLongitude, MaxLongitude);
double long2 = Clip(array[], MinLongitude, MaxLongitude);
if (level < ) level = ;
if (level > ) level = ; Console.WriteLine("Generating download list...");
List<int> list = new List<int>();
for (i = ; i <= level; ++i)
{
int x1, y1, x2, y2;
LatLongToTileXY(lat1, long1, i, out x1, out y1);
LatLongToTileXY(lat2, long2, i, out x2, out y2);
for (int u = x1; u <= x2; ++u)
for (int v = y1; v <= y2; ++v)
{
list.Add(u);
list.Add(v);
list.Add(i);
}
}
Console.WriteLine(list.Count / + " in list"); Console.WriteLine("Validating existing tiles...");
List<int> dlist = new List<int>();
for (i = ; i < list.Count; i += )
{
int x = list[i], y = list[i + ], l = list[i + ];
if (Validate(x, y, l))
continue;
dlist.Add(x);
dlist.Add(y);
dlist.Add(l);
}
Console.WriteLine(dlist.Count / + " to download");
if (dlist.Count == )
return; Console.WriteLine("Press ENTER");
Console.ReadLine();
for (i = ; i < dlist.Count; i += )
{
int x = dlist[i], y = dlist[i + ], l = dlist[i + ];
Console.Write("\rDownloading " + i / );
Download(x, y, l);
} Console.WriteLine();
Console.WriteLine("Done.");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine(ex.Message);
Console.WriteLine(ex.Source);
Console.WriteLine(ex.StackTrace);
Console.WriteLine();
}
}
}
}

Google地图下载工具代码的更多相关文章

  1. google兴趣点下载工具

    继上次百度兴趣点版本的发布以后,发现百度只能下载本国数据,并且数据完整度还是和google的少一些,所以本次经过钻研与解密,实现了google地图下载工具,版本的主要功能如下: 1.支持多线程下载,支 ...

  2. Google POI下载工具破解之路

    我是GIS初学者,爱好二次开发,像初恋一样.最近对编译感兴趣,每当成功获取一点信息,就有一种快感,感觉马上就要成功了……其实,还早! 01.初次反编译 今天在微创业工作室找到了Google POI下载 ...

  3. Cesium中文网——如何开发一款地图下载工具[一]

    Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ Cesium中文网的朋友们的其中一个主题是:自己独立开发一款地图 ...

  4. 永久免费开源的卫星地形图地图下载工具更新Somap2.13版本功能更新 更新时间2019年2月22日13:59:05

    一.下载地址 最新版本下载地址:SoMap2.13点击此处下载  二.系统自主开发特色功能展示 1.上百种地图随意下载 高德.百度.arcgis.谷歌.bing.海图.腾讯.Openstreet.天地 ...

  5. 关于无法全然下载CyanogenMod代码的问题

    CyanogenMod真的是一个奇妙的东东,它让开发手机固件不再是手机生产商的专利,每一个有志于此的程序猿都可能为自己的手机定制一份专有的,独一无二的固件,这在曾经是想都不敢想的. 而且Cyanoge ...

  6. Google 地图切片URL地址解析

    一.Google地图切片的投影方式及瓦片索引机制 1.地图投影 Google地图采用的是Web墨卡托投影(如下图),为了方便忽略了两极变形较大的地区,把世界地图做成了一个边长等于赤道周长的正方形(赤道 ...

  7. 使用QT开发GoogleMap瓦片显示和下载工具(2)——Google地图瓦片投影和获取网址解析

    这篇主要说的是Google地图采用的投影方式,瓦片划分方式以及如何从给定的经纬度获取瓦片的数据的网址.所有资料均来自于网络,并亲自试验可行. Google地图投影 首先是地图投影问题,因为地球本身是一 ...

  8. Mac下载并编译Google安卓AOSP项目代码

    Mac下载并编译Google安卓AOSP项目代码 参考 https://source.android.com/source/index.html 这两天用Mac下载安卓AOSP源码,且把遇到的问题记下 ...

  9. Google Chrome调试js代码,开发者工具之调试工具常用功能

    参考:Google Chrome调试js代码-http://www.open-open.com/lib/view/open1384785324165.html 重点:左下角一个{}括号图标按钮用于把杂 ...

随机推荐

  1. vim note (2)

    :e          edit :edit       edit :e.         edit current file '.'  a dot is means current : w writ ...

  2. Mac 开发PhoneGap 应用,怎样加入插件 barcodescaner

    搞了两天,最终悟出来了 PhoneGap 与 Cordova 的关系了,有人说是WebKit 与 Chrome 的关系,但我个人理解,两个东西再干一件事情,另外 PhoneGap 被Apache 收购 ...

  3. 图像块的访问(填充 padding,步长 stride,窗 Window/kernel/filter)

    无填充是有填充的特例(填充为 1). utilities(matlab)-- 图像分块(image2cols.cols2image)(未填充) 1. 一个图像块 ⇒ 返回一个值 输出矩阵的大小: ou ...

  4. Clustering Devices In An Internet Of Things

    Clustering devices in an Internet of Things ('IoT'), including: receiving, by a device clustering mo ...

  5. std::string 简单入门

    string的定义原型 typedef basic_string<char, char_traits<char>, allocator<char> > string ...

  6. WPF中使用TranslateTransform3D修改CAD的3D旋转中心

    原文:WPF中使用TranslateTransform3D修改CAD的3D旋转中心        前面一篇文章讲述了2D旋转功能的实现,文章提到了修改3D旋转中心,这一节主要总结一下具体的修改3D旋转 ...

  7. WPF中使用AxisAngleRotation3D实现CAD的2D旋转功能

    原文:WPF中使用AxisAngleRotation3D实现CAD的2D旋转功能       对于CAD图形来说,3D旋转比较常用,具体实现方法在上篇文章<WPF中3D旋转的实现 >中做了 ...

  8. matlab 类型转换(类型判断)

    char:Convert to character array,转换为字符数组:matlab 下没有 str 字符串类型转换: char(0-255) ⇒ ASCII 码的转换: im2double( ...

  9. 微信小程序之登录页实例

    项目效果图: 目录结构: login.wxml: <view class="container"> <view class="login-icon&qu ...

  10. python3 基本使用多线程

    #coding=utf-8 import threading #进口threading from time import sleep import time def task1(): print (& ...