C# GMap下提供一个高德地图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# GMap下提供一个高德地图相关的知识,希望对你有一定的参考价值。

using System;
using GMap.NET.Internals;
using GMap.NET.Projections;

namespace GMap.NET.MapProviders
{
    public class AMapProvider : AMapProviderBase
    {
        private readonly string name = "AMap";
        private readonly string language = "zh_cn";
        private readonly Guid id = new Guid("F81F5FB4-0902-4686-BF5B-B2B1E4D47922");
        public static readonly AMapProvider Instance;
        private Random ran = new Random();
        private static string UrlFormat = "http://webrd0{0}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={1}&y={2}&z={3}&scale=1&ltype=3";
        public string Caption
        {
            get
            {
                return "高德地图";
            }
        }
        public override Guid Id
        {
            get { return this.id; }
        }

        public override string Name
        {
            get { return this.name; }
        }

        static AMapProvider()
        {
            Instance = new AMapProvider();
        }
        public AMapProvider()
        {

        }

        public override PureImage GetTileImage(GPoint pos, int zoom)
        {
            string url = MakeTileImageUrl(pos, zoom, language);
            return GetTileImageUsingHttp(url);
        }
        //http://wprd0{0}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={1}&y={2}&z={3}&scl=2&ltype=3
        private string MakeTileImageUrl(GPoint pos, int zoom, string language)
        {
            int serverID = ran.Next(1, 5);//1-4 
            return string.Format(UrlFormat, 4, pos.X, pos.Y, zoom);
        }
    }


    public abstract class AMapProviderBase : GMapProvider
    {
        protected GMapProvider[] overlays;
        public AMapProviderBase()
        {
            RefererUrl = "http://www.amap.com/";
            Copyright = string.Format("©{0} 高德地图 GPRS(@{0})", DateTime.Today.Year);
            MinZoom = 1;
            MaxZoom = 20;
        }

        public override GMapProvider[] Overlays
        {
            get
            {
                if (overlays == null)
                {
                    overlays = new GMapProvider[] { this };
                }
                return overlays;
            }
        }

        public override PureProjection Projection
        {
            get
            {
                return MercatorProjection.Instance;
            }
        }
    }
}

 

以上是关于C# GMap下提供一个高德地图的主要内容,如果未能解决你的问题,请参考以下文章

将GMap封装为Activex供QT使用(工具:VS2017,QT5.12)

Gmap基本地图显示

高德地图的位置搜索

android开发如何用高德地图进行模拟定位.

利用高德提供的api获取行政区域查询

使用GMap.NET类库,实现地图轨迹回放。(WPF版)