How to Use GMap.NET in WinForms

Here’s a step-by-step guide to get you started:

1. Install via NuGet

In Visual Studio, open the Package Manager Console and run:

Code
Install-Package GMap.NET.WinForms
Install-Package GMap.NET.Core

This brings in the core libraries and the WinForms-specific controls.

2. Add the Map Control

  • Drag a GMapControl from the toolbox onto your form (or add it programmatically).
  • Set basic properties like Dock, MapProvider, and Position.

3. Initialize the Map

In your form’s constructor or Load event:

Code
gmap.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
gmap.Position = new GMap.NET.PointLatLng(19.2183, 72.9781); // Example: Thane coordinates
gmap.MinZoom = 1;
gmap.MaxZoom = 20;
gmap.Zoom = 12;

4. Add Markers or Routes

You can overlay markers or draw paths:

C#
var markers = new GMap.NET.WindowsForms.GMapOverlay("markers");
var marker = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(
    new GMap.NET.PointLatLng(19.2183, 72.9781),
    GMap.NET.WindowsForms.Markers.GMarkerGoogleType.red_dot);
markers.Markers.Add(marker);
gmap.Overlays.Add(markers);

 

Supported Map Providers

GMap.NET supports:

  • OpenStreetMap (free and open)
  • Bing Maps
  • Google Maps (requires API key)
  • ArcGIS, MapQuest, WikiMapia, and more

?? Resources

  • GMap.NET GitHub Repository – for source code and documentation
  • NuGet Package Page – for installation and versioning info