Click here to Skip to main content
15,881,812 members
Articles / Desktop Programming / Windows Forms

GMap.NET - Great Maps for Windows Forms and Presentation

Rate me:
Please Sign up or sign in to vote.
4.80/5 (135 votes)
16 Apr 2013MIT1 min read 1.8M   608   508   373
GMap.NET is a powerful, free, cross platform, Open Source .NET control. It enables the use of routing, geocoding, and maps from Google, Yahoo!, OpenStreet in Windows Forms and Presentation, and supports caching!

GMapNET/GMapNETv7cp.PNG

Introduction

Google Maps are cool, yeah? But it's useful only in the browser, and is insufficient for real time tracking. It also does not have cache so Google servers are overloaded. This control removes all these deficiencies! It also gives the .NET developer unlimited ability to extend it!

GMap.NET is great and Powerful, Free, cross platform, open source .NET control. Enable use routing, geocoding, directions and maps from Google, Yahoo!, Bing, OpenStreetMap, ArcGIS, Pergo, SigPac, Yandex, Mapy.cz, Maps.lt, iKarte.lv, NearMap, OviMap, CloudMade, WikiMapia, MapQuest in Windows Forms & Presentation, supports caching and runs on windows mobile! 

Background

The basic idea is simple: get the required data from Google/etc., cache it, and use it. Fast, simple, and practical.

Using the Code

It's more than easy. GMap.NET.dll and GMap.NET.WindowsForms.dll contain the user control. Add it to your project and simply use it.

Here are the basic control initial options: 

C#
public MainForm()
{

InitializeComponent();

try
{
   System.Net.IPHostEntry e =
        System.Net.Dns.GetHostEntry("www.google.com");
}
catch
{
   MainMap.Manager.Mode = AccessMode.CacheOnly;
   MessageBox.Show("No internet connection avaible, going to CacheOnly mode.", 
         "GMap.NET - Demo.WindowsForms", MessageBoxButtons.OK,
         MessageBoxIcon.Warning);
}

// config map
MainMap.MapProvider = GMapProviders.OpenStreetMap;
MainMap.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
MainMap.MinZoom = 0;
MainMap.MaxZoom = 24;
MainMap.Zoom = 9;

// add your custom map db provider
//GMap.NET.CacheProviders.MySQLPureImageCache ch = new GMap.NET.CacheProviders.MySQLPureImageCache();
//ch.ConnectionString = @"server=sql2008;User Id=trolis;Persist Security Info=True;database=gmapnetcache;password=trolis;";
//MainMap.Manager.SecondaryCache = ch;

// set your proxy here if need
//GMapProvider.WebProxy = new WebProxy("10.2.0.100", 8080);
//GMapProvider.WebProxy.Credentials = new NetworkCredential("ogrenci@bilgeadam.com", "bilgeada");

// map events
{
   MainMap.OnPositionChanged += new PositionChanged(MainMap_OnPositionChanged);

   MainMap.OnTileLoadStart += new TileLoadStart(MainMap_OnTileLoadStart);
   MainMap.OnTileLoadComplete += new TileLoadComplete(MainMap_OnTileLoadComplete);

   MainMap.OnMapZoomChanged += new MapZoomChanged(MainMap_OnMapZoomChanged);
   MainMap.OnMapTypeChanged += new MapTypeChanged(MainMap_OnMapTypeChanged);

   MainMap.OnMarkerClick += new MarkerClick(MainMap_OnMarkerClick);
   MainMap.OnMarkerEnter += new MarkerEnter(MainMap_OnMarkerEnter);
   MainMap.OnMarkerLeave += new MarkerLeave(MainMap_OnMarkerLeave);

   MainMap.OnPolygonEnter += new PolygonEnter(MainMap_OnPolygonEnter);
   MainMap.OnPolygonLeave += new PolygonLeave(MainMap_OnPolygonLeave);

   MainMap.OnRouteEnter += new RouteEnter(MainMap_OnRouteEnter);
   MainMap.OnRouteLeave += new RouteLeave(MainMap_OnRouteLeave);

   MainMap.Manager.OnTileCacheComplete += new TileCacheComplete(OnTileCacheComplete);
   MainMap.Manager.OnTileCacheStart += new TileCacheStart(OnTileCacheStart);
   MainMap.Manager.OnTileCacheProgress += new TileCacheProgress(OnTileCacheProgress);
}   
} 

As you can see, the control options are quite simple. And there is nothing more to add.

Points of Interest

Well, it was quite cryptic to figure out how Google manages tiles, what coordinate system it uses, the JSON decryption, etc.

History

Go to the project's CodePlex site to get a running update of any changes or improvements I've made.  

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: does it support Chinese version of gmap? Pin
radioman.lt26-Feb-09 3:00
radioman.lt26-Feb-09 3:00 
QuestionHow to Zoom in? Pin
transoft14-Feb-09 8:24
transoft14-Feb-09 8:24 
AnswerRe: How to Zoom in? Pin
radioman.lt14-Feb-09 9:20
radioman.lt14-Feb-09 9:20 
GeneralRe: How to Zoom in? Pin
transoft14-Feb-09 16:07
transoft14-Feb-09 16:07 
GeneralRe: How to Zoom in? Pin
radioman.lt15-Feb-09 1:02
radioman.lt15-Feb-09 1:02 
GeneralRe: How to Zoom in? Pin
transoft15-Feb-09 7:01
transoft15-Feb-09 7:01 
GeneralRe: How to Zoom in? Pin
radioman.lt15-Feb-09 9:57
radioman.lt15-Feb-09 9:57 
General1) there's no "CVS" at all.. 2) Use adds.. Pin
andré_k12-Feb-09 5:04
andré_k12-Feb-09 5:04 
Dude,
with all that we pay for Trojans, nobody will dare use such an unknown web object, without a source sure and of confidence..

Today, 2009/02/12 16h42 WET

I clicked your links for the "CVS"'s, "sources" and other "explanations" and there were open links...
Even "www.codeplex.com" alone, did not answer

So, fellow, perhaps am I wrong, but good luck for your enterprise.. here's a discussion between professionals not an arabian souk. Please erase your sh..t and get out.
GeneralRe: 1) there's no "CVS" at all.. 2) Use adds.. Pin
radioman.lt12-Feb-09 5:10
radioman.lt12-Feb-09 5:10 
GeneralMy vote of 1 Pin
Member 47156447-Feb-09 15:13
Member 47156447-Feb-09 15:13 
QuestionExport map to pdf or print Pin
Nanda5553-Feb-09 1:50
Nanda5553-Feb-09 1:50 
AnswerRe: Export map to pdf or print Pin
radioman.lt3-Feb-09 2:01
radioman.lt3-Feb-09 2:01 
GeneralRe: Export map to pdf or print Pin
Nanda5553-Feb-09 2:25
Nanda5553-Feb-09 2:25 
GeneralRe: Export map to pdf or print Pin
radioman.lt3-Feb-09 2:27
radioman.lt3-Feb-09 2:27 
QuestionWhy not a generic open TMS client application ? Pin
Alberto Armando27-Jan-09 20:52
Alberto Armando27-Jan-09 20:52 
AnswerRe: Why not a generic open TMS client application ? Pin
radioman.lt28-Jan-09 4:11
radioman.lt28-Jan-09 4:11 
GeneralRe: Why not a generic open TMS client application ? Pin
Alberto Armando30-Jan-09 3:01
Alberto Armando30-Jan-09 3:01 
GeneralRe: Why not a generic open TMS client application ? Pin
radioman.lt30-Jan-09 4:47
radioman.lt30-Jan-09 4:47 
GeneralRe: Why not a generic open TMS client application ? Pin
Alberto Armando31-Jan-09 4:13
Alberto Armando31-Jan-09 4:13 
GeneralRe: Why not a generic open TMS client application ? Pin
radioman.lt31-Jan-09 5:20
radioman.lt31-Jan-09 5:20 
GeneralRe: Why not a generic open TMS client application ? Pin
Alberto Armando1-Feb-09 3:29
Alberto Armando1-Feb-09 3:29 
GeneralRe: Why not a generic open TMS client application ? Pin
radioman.lt1-Feb-09 3:35
radioman.lt1-Feb-09 3:35 
GeneralMy vote of 2 Pin
Abhishek Sur21-Jan-09 20:04
professionalAbhishek Sur21-Jan-09 20:04 
GeneralRe: My vote of 2 Pin
Serge Desmedt31-Jan-09 8:52
professionalSerge Desmedt31-Jan-09 8:52 
GeneralMy vote of 2 Pin
Member 9619-Jan-09 5:30
Member 9619-Jan-09 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.