Click here to Skip to main content
Click here to Skip to main content

GMap.NET - Great Maps for Windows Forms and Presentation

By , 16 Apr 2013
 

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: 

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

About the Author

radioman.lt
Software Developer
Lithuania Lithuania
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberGregoryW28 Apr '13 - 23:26 
Actually gmaps.net is a bigger project with lot of options you didn't show in article.   Title says smth different to the content.
QuestionCan't Browse at CPmemberAlan Burkhart22 Apr '13 - 13:33 
In the "Browse Code" page the links are not working. The code does not display. XAlan Burkhart
AnswerRe: Can't Browse at CPmemberSteveQ5622 Apr '13 - 21:33 
Had that problem using IE.   Copied address to Chrome and no problem reading code - it's all there.   Not a Chrome fanboy - my usual browser is Opera!   Hope this helps
GeneralRe: Can't Browse at CPmemberradioman.lt22 Apr '13 - 21:35 
works just fine with opera, my favorite too ;} d{^__^}b - it's time to fly
GeneralRe: Can't Browse at CPmemberAlan Burkhart23 Apr '13 - 13:06 
I'm using Fire Fox. Will try it with Chrome. XAlan Burkhart
GeneralMy vote of 5memberPrasad Khandekar16 Apr '13 - 9:15 
Nice control. Well done,
QuestionHow to cache maps?memberS.Faizan.Ali15 Apr '13 - 19:34 
Does it cache map by default or we have to do it by code?
AnswerRe: How to cache maps?memberradioman.lt16 Apr '13 - 0:22 
cache is enabled by default, you can use integrated tile prefetcher to cache larger areas d{^__^}b - it's time to fly
QuestionMapControl does not contain the properties of MapType and CurrentPositionmemberjhyap858 Apr '13 - 15:20 
Referring to your source above, under config map.   I try to set the Maptype and CurrentPosition. But it prompts me error message saying GMap.NET.WindowsForms.GMAPControl does not contain a definition for 'Maptype'   Same problem goes to 'CurrentPosition'
AnswerRe: MapControl does not contain the properties of MapType and CurrentPositionmemberradioman.lt8 Apr '13 - 20:17 
MapType is changed to MapProvider, and just Position, check the demo source first d{^__^}b - it's time to fly
GeneralRe: MapControl does not contain the properties of MapType and CurrentPositionmemberjhyap858 Apr '13 - 21:18 
The demo source is just .exe.. Is there any possible to review some example source code? Because I just need a static map, and on the map, I marked a "source" location coordinate, and "target" location coordinate.   I had successfully add the marker of location coordinate for my "source"...
GeneralRe: MapControl does not contain the properties of MapType and CurrentPositionmemberradioman.lt8 Apr '13 - 22:23 
are you drunk? d{^__^}b - it's time to fly
GeneralRe: MapControl does not contain the properties of MapType and CurrentPositionmemberjhyap859 Apr '13 - 3:14 
=_=
GeneralRe: MapControl does not contain the properties of MapType and CurrentPositionmemberjhyap859 Apr '13 - 15:19 
How to add route using GMap control?
QuestionNo instance of MainMap or: is there any Documentation or How to? [modified]memberMember 99643873 Apr '13 - 23:33 
Hi all,   I followed the short documentation and did the following: 1. New Windows-Form Project, one Button with a OnClick-Method. 2. I referenced the two DLL, which ca be downloaded from 3. I copied the following code into the On-Click-Button-Method // set cache mode only if no...
AnswerRe: No instance of MainMap or: is there any Documentation or How to?memberradioman.lt4 Apr '13 - 4:13 
MainMap is the name of the map control, you can change it in properties window, or just check demo source d{^__^}b - it's time to fly
GeneralRe: No instance of MainMap or: is there any Documentation or How to?memberMember 99643874 Apr '13 - 5:14 
I do not find any demo source or respective project. Can you give me the link? How do I include the control, via toolbox? How do I instatiate a respective control? Thanks and regards   CJC
GeneralRe: No instance of MainMap or: is there any Documentation or How to?memberradioman.lt4 Apr '13 - 20:45 
;} d{^__^}b - it's time to fly
GeneralMy vote of 1memberrocket4225 Feb '13 - 22:52 
dont have source code
GeneralRe: My vote of 1memberradioman.lt25 Feb '13 - 23:01 
yes it does d{^__^}b - it's time to fly
Questionsaidmemberrocket4225 Feb '13 - 22:51 
this article haven't source code or documentations. SO it's value is zero. Email: hung.rocket42@gmail.com Facebook
AnswerRe: saidmemberradioman.lt25 Feb '13 - 22:57 
jealous d{^__^}b - it's time to fly
GeneralMy vote of 2memberGuillaume Waser23 Jan '13 - 22:47 
This article is just an advertising and brings nothings to a project that miss of documentation : no architecture view, no tech documentation... This does not means GMap.NET is not a good project...
GeneralRe: My vote of 2memberradioman.lt15 Feb '13 - 8:46 
be my guest and help, http://greatmaps.wikia.com/[^]   source itself is documentation, want something more bold, read the bible... d{^__^}b - it's time to fly
GeneralRe: My vote of 2memberrocket4225 Feb '13 - 23:37 
I don't see whatever source code or document in http://greatmaps.wikia.com/[^] Email: hung.rocket42@gmail.com Facebook

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 16 Apr 2013
Article Copyright 2009 by radioman.lt
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid