深入理解最强桌面地图控件GMAP.NET ---[更新]百度地图
之前写了篇博文,深入理解最强桌面地图控件GMAP.NET --- 百度地图
但是很多回复说百度地图更新了,不能显示百度的离线地图。之前承诺说是国庆节更新,最近才更新。代码已经提交到:
https://code.google.com/p/ypmap/
其实算法都是一样的,只是链接变了,
//原来:http://q3.baidu.com/it/u=x=721;y=209;z=12;v=014;type=web&fm=44
//更新:http://online1.map.bdimg.com/tile/?qt=tile&x=23144&y=6686&z=17&styles=pl
因此只要将BaiduMapProviderBase改成下面的代码即可
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Text; using System.Xml; using GMap.NET.Internals; using GMap.NET.MapProviders; using GMap.NET.Projections; namespace GMap.NET.GMap.NET.MapProviders.Baidu { public abstract class BaiduMapProviderBase : GMapProvider { private string ClientKey = "1308e84a0e8a1fc2115263a4b3cf87f1"; public BaiduMapProviderBase() { MaxZoom = null; RefererUrl = "http://map.baidu.com"; Copyright = string.Format("©{0} Baidu Corporation, ©{0} NAVTEQ, ©{0} Image courtesy of NASA", DateTime.Today.Year); } public override PureProjection Projection { get { return MercatorProjection.Instance; } } GMapProvider[] overlays; public override GMapProvider[] Overlays { get { if (overlays == null) { overlays = new GMapProvider[] { this }; } return overlays; } } } public class BaiduMapProvider : BaiduMapProviderBase { public static readonly BaiduMapProvider Instance; readonly Guid id = new Guid("608748FC-5FDD-4d3a-9027-356F24A755E5"); public override Guid Id { get { return id; } } readonly string name = "BaiduMap"; public override string Name { get { return name; } } static BaiduMapProvider() { Instance = new BaiduMapProvider(); } public override PureImage GetTileImage(GPoint pos, int zoom) { string url = MakeTileImageUrl(pos, zoom, LanguageStr); return GetTileImageUsingHttp(url); } string MakeTileImageUrl(GPoint pos, int zoom, string language) { zoom = zoom - 1; var offsetX = Math.Pow(2, zoom); var offsetY = offsetX - 1; var numX = pos.X - offsetX; var numY = -pos.Y + offsetY; zoom = zoom + 1; var num = (pos.X + pos.Y)%8 + 1; var x = numX.ToString().Replace("-", "M"); var y = numY.ToString().Replace("-", "M"); //原来:http://q3.baidu.com/it/u=x=721;y=209;z=12;v=014;type=web&fm=44 //更新:http://online1.map.bdimg.com/tile/?qt=tile&x=23144&y=6686&z=17&styles=pl string url = string.Format(UrlFormat, x, y, zoom); Console.WriteLine("url:" + url); return url; } static readonly string UrlFormat = "http://online1.map.bdimg.com/tile/?qt=tile&x={0}&y={1}&z={2}&styles=pl"; } }
posted on 2013-11-18 22:23 enjoyeclipse 阅读(7038) 评论(22) 编辑 收藏 举报