Google地图下载工具代码
//
// 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地图下载工具代码的更多相关文章
- google兴趣点下载工具
继上次百度兴趣点版本的发布以后,发现百度只能下载本国数据,并且数据完整度还是和google的少一些,所以本次经过钻研与解密,实现了google地图下载工具,版本的主要功能如下: 1.支持多线程下载,支 ...
- Google POI下载工具破解之路
我是GIS初学者,爱好二次开发,像初恋一样.最近对编译感兴趣,每当成功获取一点信息,就有一种快感,感觉马上就要成功了……其实,还早! 01.初次反编译 今天在微创业工作室找到了Google POI下载 ...
- Cesium中文网——如何开发一款地图下载工具[一]
Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ Cesium中文网的朋友们的其中一个主题是:自己独立开发一款地图 ...
- 永久免费开源的卫星地形图地图下载工具更新Somap2.13版本功能更新 更新时间2019年2月22日13:59:05
一.下载地址 最新版本下载地址:SoMap2.13点击此处下载 二.系统自主开发特色功能展示 1.上百种地图随意下载 高德.百度.arcgis.谷歌.bing.海图.腾讯.Openstreet.天地 ...
- 关于无法全然下载CyanogenMod代码的问题
CyanogenMod真的是一个奇妙的东东,它让开发手机固件不再是手机生产商的专利,每一个有志于此的程序猿都可能为自己的手机定制一份专有的,独一无二的固件,这在曾经是想都不敢想的. 而且Cyanoge ...
- Google 地图切片URL地址解析
一.Google地图切片的投影方式及瓦片索引机制 1.地图投影 Google地图采用的是Web墨卡托投影(如下图),为了方便忽略了两极变形较大的地区,把世界地图做成了一个边长等于赤道周长的正方形(赤道 ...
- 使用QT开发GoogleMap瓦片显示和下载工具(2)——Google地图瓦片投影和获取网址解析
这篇主要说的是Google地图采用的投影方式,瓦片划分方式以及如何从给定的经纬度获取瓦片的数据的网址.所有资料均来自于网络,并亲自试验可行. Google地图投影 首先是地图投影问题,因为地球本身是一 ...
- Mac下载并编译Google安卓AOSP项目代码
Mac下载并编译Google安卓AOSP项目代码 参考 https://source.android.com/source/index.html 这两天用Mac下载安卓AOSP源码,且把遇到的问题记下 ...
- Google Chrome调试js代码,开发者工具之调试工具常用功能
参考:Google Chrome调试js代码-http://www.open-open.com/lib/view/open1384785324165.html 重点:左下角一个{}括号图标按钮用于把杂 ...
随机推荐
- window.url.createobjecturl 兼容多种浏览器(IE,google,360,Safari,firefox)
<script type="text/javascript"> function setImagePreview() { var docObj = document.g ...
- 寄存器,cache、伙伴系统、内存碎片、段式页式存储管理
cache.伙伴系统.内存碎片.段式页式存储管理 目录 分层的存储管理 cache 局部性原理 置换算法 写回策略 linux环境下的cache 连续内存分配与内存碎片 内部碎片与外部碎片 动态分区分 ...
- C# opcode 查询源码
Add|将两个值相加并将结果推送到计算堆栈上.Add.Ovf|将两个整数相加,执行溢出检查,并且将结果推送到计算堆栈上.Add.Ovf.Un|将两个无符号整数值相加,执行溢出检查,并且将结果推送到计算 ...
- 让delphi2010操作界面回到delphi7模式
让delphi2010操作界面回到delphi7模式 在使用delphi2010的过程中,很不习惯它的窗口在一个框框内,感觉很不方便,可能是因为使用delphi7很多年了,已经习惯了delphi7的版 ...
- java 中的两个常用命令
这两个命令,分别为,javac 和java 实际操作如下图:
- 矩阵微分(matrix derivatives)
关于矩阵求导,得到的导数则是矩阵形式:关于矢量求导,得到的导数则是矢量形式:关于标量求导,得到的仍是标量形式.也即关于谁求导,得到的导数形式便和谁的维度信息一致. fx = f(x) grad = n ...
- centos7 Intellij Idea 授权服务器搭建(Jetbrain 家族系列IDE)
centos7 Intellij Idea 授权服务器搭建 1.上传破解文件 我用的是Xshell客户端,有上传功能,但是linux必须先装lrzsz,也可以通过其他方式传到linux上 yum -y ...
- 学习Hadoop和Spark的好的资源
1. 官网http://spark.apache.org 有各种资源链接: 2. 总结得很好的个人博客[从零开始学Hadoop系列]1)初识http://blog.csdn.net/u01016816 ...
- IEditableObject的一个通用实现
原文:IEditableObject的一个通用实现 IeditableObject是一个通用接口,用于支持对象编辑.当我们在界面上选择一个条目,然后对其进行编辑的时候,接下来会有两种操作,一个是保持编 ...
- 【STL】关联容器 — hashtable
C++ 11哈希表已被列入标准列.hashtable这是hash_set.hash_map.hash_multiset.hash_multimap的底层机制.即这四种容器中都包括一个hashtable ...