2016-08-30 1 views
-1

私はSharpMapを初めて使用しており、GISを使用した経験は一度もありませんでした。
sharpmapにGoogleマップを表示させ、緯度と経度の値を使っていくつかのポイントを表示するにはどうすればよいですか? (例:ポイント1の緯度:-36.853427、経度:174.770385、ポイント2の緯度:-36.853333、ロング:174.770496)。
私は本当に立ち往生しており、深く感謝しています。SharpMapを使用してGoogleマップレイヤーを表示するにはどうすればよいですか?

は、ここで私がこれまで持っているものです。

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 
     } 
    } 

}

+0

GoogleのTOSに反するhttps://developers.google.com/maps/faq#tos_tiles – Goldorak84

答えて

0

私はちょうどあなたがgoogletileマップを作成するには、このコードを使用することができ、Googleマップライセンス
に対する教育purpose..Itsのためにこれを共有しています

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

CreateGoogleTileSource

を以下のようです10
private static ITileSource CreateGoogleTileSource(string urlFormatter) 
    { 
     return new HttpTileSource(new GlobalSphericalMercator(), urlFormatter, new[] { "0", "1", "2", "3" }, 
      tileFetcher: FetchImageAsGoogle()); 
    } 

FetchImageAsGoogleはgithubのからsharpmapとSharpMap.Layers.BruTileの最後のバージョンを使用して心の中で

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; 
        } 
       }; 

    } 

ベアようです。

+0

GoogleのTOS developers.google.com/maps/faq#tos_tiles - Goldorak84 – Goldorak84

+1

@ Goldorak84これを共有しています教育目的のために。 –

関連する問題