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 重点:左下角一个{}括号图标按钮用于把杂 ...
随机推荐
- Video processing systems and methods
BACKGROUND The present invention relates to video processing systems. Advances in imaging technology ...
- Spring+SpringMVC+MyBatis+easyUI
Spring+SpringMVC+MyBatis+easyUI 日常啰嗦 还好在第一篇文章里就列好了接下来的主线及要写的知识点,不然都不知道要写什么东西了,开篇里已经列了基础篇要讲svn和git的知识 ...
- abmr:块恢复特性测试自己主动
abmr:块恢复特性测试自己主动 参考原始: ABMR: How to test Automatic Block Recover Feature (Doc ID 1266059.1) 可适用: Ora ...
- VC++实现Vista和Win7系统低权限程序向高权限程序发消息
Windows 7已经隆重发布,但是很多程序员已经通过RTM等版本尝到了Windows 7的甜处.那么在Windows 7下用户界面特权隔离,将是本文我们介绍的重点. 我们介绍了操作系统服务的Sess ...
- 将 WPF、UWP 以及其他各种类型的旧 csproj 迁移成基于 Microsoft.NET.Sdk 的新 csproj
原文 将 WPF.UWP 以及其他各种类型的旧 csproj 迁移成基于 Microsoft.NET.Sdk 的新 csproj 写过 .NET Standard 类库或者 .NET Core 程序的 ...
- WPF 导出资源文件
在wpf开发中我们可以把各种文件.图片打包到项目中也就是应用程序资源文件,然后在项目中可以通过特定的uri格式去调用.那有些时候为了方便我们可能想要在程序中将资源文件导出来使用,那么怎么做呢? 第 1 ...
- blockchain_eth客户端安装 & geth使用 &批量转账(二)
回顾一下,前面我们讲到启动geth geth --rpc --datadir "F:/geth/Geth/" --light console 2>console.log 这一 ...
- 汉顺平html5课程分享:6小时制作经典的坦克大战!
记起自己去年參加的一次面试,在做过Java多年的面试官面前发挥的并不好,但他一听说我会html5,立刻眼睛发亮.无论不顾的想要和我签约.. .所以.如今为工作犯愁的朋友们,学好html5,绝对会为你找 ...
- CheckBox IsHitTestVisible
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"></Colu ...
- JS超链接动态显示图片
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...