Click here to Skip to main content
15,120,478 members
Articles / Desktop Programming / Windows Forms
Article
Posted 18 Jan 2009

Stats

1.5M views
545 downloads
506 bookmarked

GMap.NET - Great Maps for Windows Forms and Presentation

Rate me:
Please Sign up or sign in to vote.
4.80/5 (132 votes)
16 Apr 2013MIT1 min read
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

Share

About the Author

radioman.lt
Software Developer
Lithuania Lithuania
No Biography provided

Comments and Discussions

 
QuestionHow does this translate between images/pixels & latitude/longitude? I'm using this to load a set of local images that make up one large image, and I'm having trouble ensuring it's centered for all zoom levels. Pin
CalicoSkies15-Dec-20 10:47
MemberCalicoSkies15-Dec-20 10:47 
QuestionMap is not loaded fully, half blue and white screen coming only Pin
tibrewalalokmit28-Sep-20 21:32
Membertibrewalalokmit28-Sep-20 21:32 
Questionc# - GMap.NET - Show tooltip below the line Pin
md384822-Aug-20 1:51
Membermd384822-Aug-20 1:51 
AnswerRe: c# - GMap.NET - Show tooltip below the line Pin
OriginalGriff22-Aug-20 1:54
mveOriginalGriff22-Aug-20 1:54 
AnswerRe: c# - GMap.NET - Show tooltip below the line Pin
md38485-Sep-20 3:04
Membermd38485-Sep-20 3:04 
QuestionBest way to import large images Pin
EricBourque2919-Aug-20 14:39
MemberEricBourque2919-Aug-20 14:39 
QuestionMap Cache Write Speed/Performance Pin
TheNeil_200116-Jul-20 2:35
MemberTheNeil_200116-Jul-20 2:35 
QuestionBeware of gmap fake clone website, make sure you download the real one Pin
SeaWater3-Dec-19 2:53
MemberSeaWater3-Dec-19 2:53 
AnswerRe: Beware of gmap fake clone website, make sure you download the real one Pin
radioman.lt13-Mar-20 9:08
Memberradioman.lt13-Mar-20 9:08 
QuestionProjection for WebService: Tile Matrix with EPSG:3857 Pin
MarioRainer19-May-19 10:25
MemberMarioRainer19-May-19 10:25 
QuestionHow do i cluster larger marker? Pin
Member 1188616610-Apr-19 16:50
MemberMember 1188616610-Apr-19 16:50 
QuestionBearing Pin
petrbrotanek26-Jun-18 5:48
Memberpetrbrotanek26-Jun-18 5:48 
AnswerRe: Bearing Pin
Member 1188616610-Apr-19 22:50
MemberMember 1188616610-Apr-19 22:50 
QuestionHow to confirm if license information added to the code is incorporated for WPF Pin
Member 136639834-May-18 5:40
MemberMember 136639834-May-18 5:40 
QuestionHow to address individual marker? Pin
Member 1170993016-Jan-18 12:31
MemberMember 1170993016-Jan-18 12:31 
QuestionAnyone done anything with Marker clustering? Pin
Member 1170993016-Jan-18 12:24
MemberMember 1170993016-Jan-18 12:24 
QuestionHow to pass credentials for BingMaps? Linqpad sample? Pin
Member 1330860613-Jul-17 7:44
MemberMember 1330860613-Jul-17 7:44 
SuggestionCould you provide links for examples of drawing a vector layer on top map source? Pin
Dan Randolph27-Apr-17 10:23
MemberDan Randolph27-Apr-17 10:23 
This app is truly amazing to support all these published map sources. Can you provide any links for examples of vector drawing on top map layers? I need to do this in a WPF desktop app and I'm not good with WPF event handling. Thank you. Cool | :cool:
AnswerRe: Could you provide links for examples of drawing a vector layer on top map source? Pin
Dan Randolph27-Apr-17 12:12
MemberDan Randolph27-Apr-17 12:12 
QuestionUsing Satellite map other than Bing Pin
Member 1311876410-Apr-17 5:09
MemberMember 1311876410-Apr-17 5:09 
QuestionGmap Control shows no more the "standard" openstreetmap Pin
Member 1271736112-Mar-17 4:10
MemberMember 1271736112-Mar-17 4:10 
AnswerRe: Gmap Control shows no more the "standard" openstreetmap Pin
Member 956324312-Mar-17 4:36
MemberMember 956324312-Mar-17 4:36 
GeneralRe: Gmap Control shows no more the "standard" openstreetmap Pin
Member 1271736129-Oct-17 9:45
MemberMember 1271736129-Oct-17 9:45 
QuestionTilt Map Pin
Member 42973466-Aug-14 17:27
MemberMember 42973466-Aug-14 17:27 
QuestionReally wished this worked. Pin
microvb27-Jul-14 8:22
Membermicrovb27-Jul-14 8:22 

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.