Google 地图下载工具 (C#)
//
// 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 = 6378137;const double MinLatitude = -85.05112878;const double MaxLatitude = 85.05112878;const double MinLongitude = -180;const double MaxLongitude = 180;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 + 180) / 360;double sinLatitude = Math.Sin(latitude * Math.PI / 180);double y = 0.5 - Math.Log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);uint mapSize = 1u << levelOfDetail;tileX = (int)Clip(x * mapSize + 0.5, 0, mapSize - 1);tileY = (int)Clip(y * mapSize + 0.5, 0, mapSize - 1);}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 == 256 && bmp.Width == 256);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(4), x, y, l,SourceTail.Substring(0, 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[4];int level = 1, i = 0;string[] splits = Console.ReadLine().Split(' ', ',');foreach (string s in splits){if (s.Trim() == "")continue;if (i < 4) array[i++] = double.Parse(s);else level = int.Parse(s);}double lat1 = Clip(array[0], MinLatitude, MaxLatitude);double lat2 = Clip(array[2], MinLatitude, MaxLatitude);double long1 = Clip(array[1], MinLongitude, MaxLongitude);double long2 = Clip(array[3], MinLongitude, MaxLongitude);if (level < 1) level = 1;if (level > 19) level = 19;Console.WriteLine("Generating download list...");List<int> list = new List<int>();for (i = 1; 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 / 3 + " in list");Console.WriteLine("Validating existing tiles...");List<int> dlist = new List<int>();for (i = 0; i < list.Count; i += 3){int x = list[i], y = list[i + 1], l = list[i + 2];if (Validate(x, y, l))continue;dlist.Add(x);dlist.Add(y);dlist.Add(l);}Console.WriteLine(dlist.Count / 3 + " to download");if (dlist.Count == 0)return;Console.WriteLine("Press ENTER");Console.ReadLine();for (i = 0; i < dlist.Count; i += 3){int x = dlist[i], y = dlist[i + 1], l = dlist[i + 2];Console.Write("\rDownloading " + i / 3);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 地图下载工具 (C#)相关推荐
- 自己做的Google地图下载工具(一)
一直都有Google地图下载的需要,这个周末加了个班, 自己实现了个VC版本的Google地图下载工具,简单实用,能用了. 至于为什么要自己实现,也是出于无奈,谁也不愿意重复造轮子. 在sourefo ...
- Google Maps Download Tool 谷歌地图下载工具
谷歌地图下载工具可下载谷歌影像图.地形图.交通路线图的瓦片图片数据,瓦片等级可任意选择1~19级,虽然20~22级地图也可以下载: 但地图分辨率和19级没啥区别,建议下载到19级即可. ...
- Google地图下载
Google地图下载 谷歌地图是在线地图,然而有些时候我们需要将其下载到本地进行相关操作和使用,截图再拼接固然很好,但是不精确和效率低,本程序将下载指定区域地图到本地.此文将回顾并记录其中下载历程,进 ...
- Google 图片下载工具
毕设做实验需要从网上下几万张图片,以前用师兄做的Flickr下载器,用Flickr的API完成的.但是Flickr上的图片是用户分享居多,通过指定的关键词去搜索,很多时候无法得到满意的图片.在Goog ...
- Python 写的 Google Map 地图下载工具
GoogleMap的切片地址改变了,以下内容已成历史:) 我们最近的遥感实习要做野外调绘,没想到老师给的图竟然比 Google Map 上的图还要旧,想想干脆就把 Google Map 上的图下载下来 ...
- 全能google地图下载器—原理
卫星地图底图地址:http://khm1.googleapis.com/kh?v=108&hl=zh-CN&x=13&y=7&z=4&token=127641 ...
- 【PC工具】离线地图图片地图瓦片下载神器map-download地图下载器
微信关注 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 最近玩邻国大神的在M5core2上显示地图,类似手机上的导航软件,可以放大缩小,左右移 ...
- Planet比Google earth更好用的地图下载神器Basemaps Viewer不用写代码全球高清影像框选下载tif格式
最近发现了一款非常好用的地图下载神器,只要在网页上进行即可,所使用的是微软的星星计划 Planet中Basemaps Viewer,利用跟这个我们可以下载赤道附近热带区域的最新高分辨率地图大概分辨率在 ...
- 【数据工具】高德地图POI数据下载工具(支持选择省市以及POI类型)
1. 工具介绍 今天分享一个能够实现零代码获取高德地图POI数据的工具. 该工具目前支持通过框选地图以及点选省或市的方式输入数据下载范围.另外,支持通过点选的方式选择想要获取的POI类型. 获取方式在 ...
最新文章
- 分布式系统关注点:无状态
- 基于jsp的网上商城_[源码和文档分享]基于S2SH框架的JSP和MySQL的网上商城系统
- linux下安装c/c++环境(gcc/gcc+)
- C#软件开发实例.私人订制自己的屏幕截图工具(十)在截图中包括鼠标指针形状...
- 效果图底图 线框图_5分钟的线框图教程
- [css] 什么是视差滚动?如何实现视差滚动的效果?
- 马后炮之12306抢票工具(四)--抢票Demo,2014年1月9日终结版
- 【转】大厦将倾,互联网将如何变革传统行业(上)
- vs2008 MFC访问Access 2010数据库
- 前端实现在线预览word(docx),pdf,excel类型的文件
- 电阻用计算机怎么算,电阻分压计算器
- sketch如何做设计稿交互_sketch交互点击视觉标注方法|sketch如何实现交互点击的视觉标注 - PS下...
- java图形用户界面设计
- python 学生成绩统计
- python 培训教程
- Ajax案例之聊天机器人
- vba按原格式批量合并word文档
- 360°全景影像建库流程
- 微信小程序登录授权{errcode:40013,errmsg:invalid appid, hints: [ req_id: qECcC0yFe-_ ]}问题
- 台式台式计算机型号怎么看,怎么查看电脑的型号和配置,台式电脑设备型号在哪里看...