主要参考网址
http://www.cnblogs.com/luxiaoxun/p/3802559.html
http://www.cnblogs.com/luxiaoxun/p/3463250.html
http://blog.csdn.net/onepiecehuiyu/article/details/19159565
GMap官方网址
http://greatmaps.codeplex.com/
WGS84,GCJ02,BD09坐标转换
http://blog.csdn.net/ma969070578/article/details/41013547
GMap总结
http://wenku.baidu.com/link?url=0JOy2cyTf8RUokKbfDelzSs29pvPnuzRNLqcT5VM451bnfKZ-gBmCg3QOFyuFut2zep_qBfp2bqqsQnaAHNGBdG5kVZoIvt8Rhgdg3raOdy
http://wenku.baidu.com/link?url=OKVBEUV5ekfPEcSRRdUyBAG6PN4Lh330gUZogBv30L92pgJECvvDPZ4hcz7h8XAt4SBw-9sTxDddeleYHvbYtDe2Y9vKtlvY2d_Pd-n4V9C
下面介绍如何在GMap.net官方控件的基础上添加国内高德地图以及添加墨卡托mercator坐标系在中国的翻版GCJ02转换投影
因为基本所有的gps芯片获取的都是wgs84坐标系数据,但是google中国,高德地图都是用的wgs84经过gcj02转换的投影,所以gmap.net获取gps数据后再地图上显示时,需要使用gcj的投影,而官方的GMap.net控件中只是标准的mercator投影
从官网下载GMap.net控件,里面是没有高德地图的所以需要添加,并且原来官方控件中是没有MercatorProjectionGCJ投影换算的。
1,http://greatmaps.codeplex.com/ 官网下载GMap.net控件
2,在GMap.NET.MapProviders文件夹下,建立AMap文件夹,在该文件夹下新建AMapProvider.cs AMapSateliteProvider.cs文件,如图所示
AMapProvider.cs文件
using System;
using GMap.NET;
using GMap.NET.MapProviders;
using GMap.NET.Projections;namespace GMap.NET.MapProviders
{public abstract class AMapProviderBase : GMapProvider{private GMapProvider[] overlays;public AMapProviderBase(){this.MaxZoom = null;base.RefererUrl = "http://www.amap.com/";base.Copyright = string.Format("©{0} 高德软件 Image© DigitalGlobe & chinasiwei | AIRBUS & EastDawn", DateTime.Today.Year);}public override GMapProvider[] Overlays{get{if (this.overlays == null){this.overlays = new GMapProvider[] { this };}return this.overlays;}}public override PureProjection Projection{get{return MercatorProjectionGCJ.Instance;}}}public class AMapProvider : AMapProviderBase{private readonly Guid id = new Guid("EF3DD303-3F74-4938-BF40-232D0595EE88");public static readonly AMapProvider Instance = new AMapProvider();//private readonly string name = Resources.Strings.AMap;private readonly string name = "AMap";private static readonly string UrlFormat = "http://webrd04.is.autonavi.com/appmaptile?x={0}&y={1}&z={2}&lang=zh_cn&size=1&scale=1&style=7";public override PureImage GetTileImage(GPoint pos, int zoom){string url = this.MakeTileImageUrl(pos, zoom, GMapProvider.LanguageStr);return base.GetTileImageUsingHttp(url);}private string MakeTileImageUrl(GPoint pos, int zoom, string language){string str = string.Format(UrlFormat, pos.X, pos.Y, zoom);Console.WriteLine("url:" + str);return str;}public override Guid Id{get{return this.id;}}public override string Name{get{return this.name;}}}}AMapSateliteProvider.cs文件如下
namespace GMap.NET.MapProviders
{using GMap.NET;using System;public class AMapSateliteProvider : AMapProviderBase{private readonly Guid id = new Guid("FCA94AF4-3467-47c6-BDA2-6F52E4A145BC");public static readonly AMapSateliteProvider Instance = new AMapSateliteProvider();//private readonly string name = Resources.Strings.AMapSatellite;private readonly string name = "AMapSatellite";private static readonly string UrlFormat = "http://webst04.is.autonavi.com/appmaptile?x={0}&y={1}&z={2}&lang=zh_cn&size=1&scale=1&style=6";public override PureImage GetTileImage(GPoint pos, int zoom){string url = this.MakeTileImageUrl(pos, zoom, GMapProvider.LanguageStr);return base.GetTileImageUsingHttp(url);}private string MakeTileImageUrl(GPoint pos, int zoom, string language){string str = string.Format(UrlFormat, pos.X, pos.Y, zoom);Console.WriteLine("url:" + str);return str;}public override Guid Id{get{return this.id;}}public override string Name{get{return this.name;}}}
}
3,在GMap.NET.Projections文件夹下添加MercatorProjectionGCJ.cs文件如下
namespace GMap.NET.Projections
{using GMap.NET;using System;public class MercatorProjectionGCJ : PureProjection{internal double a = 6378245.0;internal double ee = 0.0066934216229659433;public static readonly MercatorProjectionGCJ Instance = new MercatorProjectionGCJ();private static readonly double MaxLatitude = 85.05112878;private static readonly double MaxLongitude = 180.0;private static readonly double MinLatitude = -85.05112878;private static readonly double MinLongitude = -180.0;private readonly GSize tileSize = new GSize(0x100L, 0x100L);public override GPoint FromLatLngToPixel(double lat, double lng, int zoom){double[] latlng = new double[2];this.transform(lat, lng, latlng);lat = latlng[0];lng = latlng[1];GPoint empty = GPoint.Empty;lat = PureProjection.Clip(lat, MinLatitude, MaxLatitude);lng = PureProjection.Clip(lng, MinLongitude, MaxLongitude);double num = (lng + 180.0) / 360.0;double num2 = Math.Sin((lat * 3.1415926535897931) / 180.0);double num3 = 0.5 - (Math.Log((1.0 + num2) / (1.0 - num2)) / 12.566370614359172);GSize tileMatrixSizePixel = this.GetTileMatrixSizePixel(zoom);long width = tileMatrixSizePixel.Width;long height = tileMatrixSizePixel.Height;empty.X = (long)PureProjection.Clip((num * width) + 0.5, 0.0, (double)(width - 1L));empty.Y = (long)PureProjection.Clip((num3 * height) + 0.5, 0.0, (double)(height - 1L));return empty;}public override PointLatLng FromPixelToLatLng(long x, long y, int zoom){PointLatLng empty = PointLatLng.Empty;GSize tileMatrixSizePixel = this.GetTileMatrixSizePixel(zoom);double width = tileMatrixSizePixel.Width;double height = tileMatrixSizePixel.Height;double num3 = (PureProjection.Clip((double)x, 0.0, width - 1.0) / width) - 0.5;double num4 = 0.5 - (PureProjection.Clip((double)y, 0.0, height - 1.0) / height);empty.Lat = 90.0 - ((360.0 * Math.Atan(Math.Exp((-num4 * 2.0) * 3.1415926535897931))) / 3.1415926535897931);empty.Lng = 360.0 * num3;PointLatLng lng2 = new PointLatLng();double[] latlng = new double[2];this.transform(empty.Lat, empty.Lng, latlng);lng2.Lat = latlng[0];lng2.Lng = latlng[1];empty.Lat -= lng2.Lat - empty.Lat;empty.Lng -= lng2.Lng - empty.Lng;return empty;}public override GSize GetTileMatrixMaxXY(int zoom){long num = ((int)1) << zoom;return new GSize(num - 1L, num - 1L);}public override GSize GetTileMatrixMinXY(int zoom){return new GSize(0L, 0L);}private static bool outOfChina(double lat, double lon){if (((lon >= 72.004) && (lon <= 137.8347)) && ((lat >= 0.8293) && (lat <= 55.8271))){return false;}return true;}private void transform(double wgLat, double wgLon, double[] latlng){if (outOfChina(wgLat, wgLon)){latlng[0] = wgLat;latlng[1] = wgLon;}else{double num = this.transformLat(wgLon - 105.0, wgLat - 35.0);double num2 = this.transformLon(wgLon - 105.0, wgLat - 35.0);double a = (wgLat / 180.0) * 3.1415926535897931;double d = Math.Sin(a);d = 1.0 - ((this.ee * d) * d);double num5 = Math.Sqrt(d);num = (num * 180.0) / (((this.a * (1.0 - this.ee)) / (d * num5)) * 3.1415926535897931);num2 = (num2 * 180.0) / (((this.a / num5) * Math.Cos(a)) * 3.1415926535897931);latlng[0] = wgLat + num;latlng[1] = wgLon + num2;}}private double transformLat(double x, double y){double num = ((((-100.0 + (2.0 * x)) + (3.0 * y)) + ((0.2 * y) * y)) + ((0.1 * x) * y)) + (0.2 * Math.Sqrt(Math.Abs(x)));num += (((20.0 * Math.Sin((6.0 * x) * 3.1415926535897931)) + (20.0 * Math.Sin((2.0 * x) * 3.1415926535897931))) * 2.0) / 3.0;num += (((20.0 * Math.Sin(y * 3.1415926535897931)) + (40.0 * Math.Sin((y / 3.0) * 3.1415926535897931))) * 2.0) / 3.0;return (num + ((((160.0 * Math.Sin((y / 12.0) * 3.1415926535897931)) + (320.0 * Math.Sin((y * 3.1415926535897931) / 30.0))) * 2.0) / 3.0));}private double transformLon(double x, double y){double num = ((((300.0 + x) + (2.0 * y)) + ((0.1 * x) * x)) + ((0.1 * x) * y)) + (0.1 * Math.Sqrt(Math.Abs(x)));num += (((20.0 * Math.Sin((6.0 * x) * 3.1415926535897931)) + (20.0 * Math.Sin((2.0 * x) * 3.1415926535897931))) * 2.0) / 3.0;num += (((20.0 * Math.Sin(x * 3.1415926535897931)) + (40.0 * Math.Sin((x / 3.0) * 3.1415926535897931))) * 2.0) / 3.0;return (num + ((((150.0 * Math.Sin((x / 12.0) * 3.1415926535897931)) + (300.0 * Math.Sin((x / 30.0) * 3.1415926535897931))) * 2.0) / 3.0));}public override double Axis{get{return 6378137.0;}}public override RectLatLng Bounds{get{return RectLatLng.FromLTRB(MinLongitude, MaxLatitude, MaxLongitude, MinLatitude);}}public override double Flattening{get{return 0.0033528106647474805;}}public override GSize TileSize{get{return this.tileSize;}}}
}
4,编译,在bin/Debug文件夹下生成GMap.NET.Core.dll文件,然后在工程中引用这个dll文件,即可出现高德地图


















