0

我是SharpMap的新手 ,从来没有使用过任何 GIS 的经验。
如何让 sharpmap 显示谷歌地图,然后使用纬度和经度值在其上显示一些点?(例如:点 1 纬度:-36.853427,经度:174.770385;点 2 纬度:-36.853333,经度:174.770496)。
我真的被困住了,非常感谢任何帮助。

这是我到目前为止所拥有的:

using System;
using System.Drawing;
using System.Windows.Forms;
using SharpMap.Layers;
using BruTile.Web;

namespace sharp_map_test
{
    public partial class Form1 : Form
    {
        double point1Lat = -36.853427;
        double point1Long = 174.770385;
        double point2Lat = -36.853333;
        double point2Long = 174.770496;

        public Form1()
        {
            InitializeComponent();

            SharpMap.Map myMap = new SharpMap.Map(new Size(400, 300));
            // Output size
            myMap.Size = new System.Drawing.Size(300, 200);

            // Minimum zoom allowed
            myMap.MinimumZoom = 100;
            // Set background
            myMap.BackColor = Color.White;

            var layergoogle = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "googlemaps");
            var layer = new VectorLayer("test");
            myMap.Layers.Add(layergoogle);

            // Render the map
            myMap.ZoomToExtents();
            System.Drawing.Image imgMap = myMap.GetMap();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Display point1Lat and point1Long point on the google map
            // Add text saying "Device A" to the point.

            // Display point2Lat and point2Long point on the google map
            // Add text saying "Device B" to the point.

            // Refresh map and get the correct zoom level
        }
    }

}

4

1 回答 1

2

我只是出于教育目的分享它..它违反谷歌地图许可证
您可以使用此代码创建一个 googletile 地图

map.BackgroundLayer.Clear();
        var GoogleSatellitesource = CreateGoogleTileSource("http://mt{s}.google.com/vt/lyrs=m@130&hl=en&x={x}&y={y}&z={z}");
        TileAsyncLayer GoogleSatellite = new SharpMap.Layers.TileAsyncLayer(GoogleSatellitesource, "GoogleSatellite");
        map.BackgroundLayer.Add(GoogleSatellite);

CreateGoogleTileSource如下

 private static ITileSource CreateGoogleTileSource(string urlFormatter)
    {
        return new HttpTileSource(new GlobalSphericalMercator(), urlFormatter, new[] { "0", "1", "2", "3" },
            tileFetcher: FetchImageAsGoogle());
    }

并且FetchImageAsGoogle

 private static Func<Uri, byte[]> FetchImageAsGoogle()
    {

            return uri =>
                {
                    var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
                    httpWebRequest.UserAgent =
                        @"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
                    httpWebRequest.Referer = "http://maps.google.com/";
                    try
                    {
                        return RequestHelper.FetchImage(httpWebRequest);
                    }
                    catch (Exception ex)
                    {


                        return null;
                    }
                };

    }

请记住,使用最新版本的 sharpmap 和SharpMap.Layers.BruTile来自 github。

于 2016-11-01T22:11:44.030 回答