C# - GMap.Net How to set it up
GMap.NET is great and Powerful, Free, cross platform, open source .NET control. Enable use routing, geocoding, directions and maps from Coogle, Yahoo!, Bing, OpenStreetMap, ArcGIS, Pergo, SigPac, Yendux, Mapy.cz, Maps.lt, iKarte.lv, NearMap, OviMap, CloudMade, WikiMapia, MapQuest in Windows Forms & Presentation, supports caching and runs on windows mobile!
http://greatmaps.codeplex.com/
And with this, I will show you, how the map can be setup quickly.
Update 25/9/2017: If you want me to create another tutorial for gmap, let me know through comments.
** You will be needing the latest source from radioman at codeplex. Get it here: http://greatmaps.codeplex.com/SourceControl/latest
Create a new project in visual studio.
Import Core module and windows forms:
You will be needing core for all the underlying references, and winforms for your frontend.
In the toolbox, right click one of the tools, it doesn't really matter which. And select "Choose items"
Press Browse under ".NET Framework components" Find your winforms DLL file. (greatmaps_3660acb94e16\GMap.NET.WindowsForms\bin\Debug) If you cannot find it under debug, please rebuild your winform, to generate the DLL file.
You can now select the control in your toolbox:
Drag it onto your From1.
Go to reference in your project and press add. Select Solution and check off Core and winforms so its part of your project and loads the dll files when edited.
Time to start coding. View code for your main form or press F7.
Lets start by adding overlays. Place them in the Form1 class:
// layers main map
readonly GMapOverlay top = new GMapOverlay();
internal readonly GMapOverlay objects = new GMapOverlay("objects");
internal readonly GMapOverlay routes = new GMapOverlay("routes");
internal readonly GMapOverlay polygons = new GMapOverlay("polygons");
This create our overlay objects from GMapOverlay, which just is layers upon layers to the main map.
In your main form method add a current marker:
currentMarker = new GMarkerGoogle(gMapControl1.Position, GMarkerGoogleType.arrow);
currentMarker.IsHitTestVisible = false;
top.Markers.Add(currentMarker);
Time to config the map it self:
// config map
gMapControl1.Manager.Mode = GMap.NET.AccessMode.ServerAndCache;
gMapControl1.MapProvider = GMapProviders.OpenStreetMap;
gMapControl1.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
gMapControl1.MinZoom = 0;
gMapControl1.MaxZoom = 24;
gMapControl1.Zoom = 3;
gMapControl1.ShowTileGridLines = true;
//gMapControl1.ScaleMode = ScaleModes.Fractional;
Last we add the overlays to gmapcontrol1.
gMapControl1.Overlays.Add(top);
gMapControl1.Overlays.Add(routes);
gMapControl1.Overlays.Add(polygons);
gMapControl1.Overlays.Add(objects);
Go ahead and press F5. You should now be able to see the map with a green arrow around africa.
public partial class MainForm : Form
{
// layers main map
readonly GMapOverlay top = new GMapOverlay();
internal readonly GMapOverlay objects = new GMapOverlay("objects");
internal readonly GMapOverlay routes = new GMapOverlay("routes");
internal readonly GMapOverlay polygons = new GMapOverlay("polygons");
GMarkerGoogle currentMarker;
public MainForm()
{
InitializeComponent();
{
// Main Map
// set current marker
currentMarker = new GMarkerGoogle(gMapControl1.Position, GMarkerGoogleType.arrow);
currentMarker.IsHitTestVisible = false;
top.Markers.Add(currentMarker);
// config map
gMapControl1.Manager.Mode = GMap.NET.AccessMode.ServerAndCache;
gMapControl1.MapProvider = GMapProviders.OpenStreetMap;
gMapControl1.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
gMapControl1.MinZoom = 0;
gMapControl1.MaxZoom = 24;
gMapControl1.Zoom = 3;
gMapControl1.ShowTileGridLines = true;
gMapControl1.Overlays.Add(top);
gMapControl1.Overlays.Add(routes);
gMapControl1.Overlays.Add(polygons);
gMapControl1.Overlays.Add(objects);
}
}