//
// 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. Cordova之打包签名apk

    首先是关于apk签名,Android程序的安装是以包名(package name)进行区分的,就是同样的包名会被认作是同一个程序.这样就可以进行升级.替换.但是包名是一个可以被查看的字符串,这样就可能 ...

  2. 探究Promise的实现

    最终答案在一个类库里,地址 https://github.com/yahoo/ypromise 这个类库也有问题,就是下面这道面试题在IE9里实现不一致,类库里还是用了setTimeout.去年尝试用 ...

  3. options.parse === void 0

    if (options.parse === void 0) options.parse = true; https://developer.mozilla.org/zh-CN/docs/Web/Jav ...

  4. C++中的模板编程

    一,函数模板 1.函数模板的概念 C++中提供了函数模板,所谓函数模板,实际上是建立一个通用函数,其函数的返回值类型和函数的参数类型不具体指定,用一个虚拟的类型来表示.这个通用函数就被称为函数的模板. ...

  5. 绝对和相对误差(absolute & relative error)

    1. 标量 真实值为 x,测量值为 x0, 绝对误差(absolute error):Δx=x0−x(有单位): 相对误差(relative error):δx=Δxx=x0−xx=x0x−1(是一个 ...

  6. Blend_ControlTemplate(Z)

    原文:Blend_ControlTemplate(Z) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010265681/article/deta ...

  7. AdaBoost算法原理及OpenCV实例

    备注:OpenCV版本 2.4.10 在数据的挖掘和分析中,最基本和首要的任务是对数据进行分类,解决这个问题的常用方法是机器学习技术.通过使用已知实例集合中所有样本的属性值作为机器学习算法的训练集,导 ...

  8. svm资料收集

    向量点乘(内积)和叉乘(外积.向量积)概念及几何意义解读: https://blog.csdn.net/dcrmg/article/details/52416832 三角形余弦定理:https://z ...

  9. google 搜索结果在新标签中打开

    google->setting->search setting->Where results open->检查

  10. WPF Timeline简易时间轴控件的实现

    原文:WPF Timeline简易时间轴控件的实现 效果图: 由于整个控件是实现之后才写的教程,因此这里记录的代码是最终实现后的,前后会引用到其他的一些依赖属性或者代码,需要阅读整篇文章. 1.确定T ...