This tutorial is specially made for a member in my team Explorer who has the task to locate the position of our robot in a map.
gmap.net is a great .net framework nonetheless it lacks of documentation.
So what I'm going to do is to show you how to refer gmap.net in your application and how to locate something in the world map.
So let's get started!
First of all we need to download the binary package which contains all the *.dll that we need.
http://greatmaps.codeplex.com/releases/view/20235#DownloadId=67818
extract the folder in a decent place, say for exemple c:\\projects\
we will need only 2 files:
GMap.NET.Core.dll
GMap.NET.WindowsForms.dll
Now we will add the GMap.NET.WindowsForms.dll to our Visual Studio IDE toolbox.
to do so go to tools-->choose toolbox items
before clicking brows, make sure you selected the ".NET Framework Components"
Select the Gmap.NET.WindowsForms.dll
click Open or "ouvrir" the click ok
now go to your toolbox (view-->toolbox) you should find a new control the "GmapControl".
Next step is even more simple :))
we need to add a reference to our new library in our projects so go to:
(view-->Solution explorer)
Select the GMap.NET.Core.dll click Ok
Note that the reference are being added to your projects reference,
we can now go back to the design and set our gmap control
Right click on the control and choose "propoerties"
In the properties windows set the Name to "mapexplr"
Finally we can start coding
Add these lines to the using lines
using GMap.NET.WindowsForms;
using GMap.NET;
using GMap.NET.MapProviders;
The Code
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
GMapOverlay overlayOne;
String contry;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void mapexplr_Load(object sender, EventArgs e)
{
//initialisation de notre map
mapexplr.SetCurrentPositionByKeywords("Tunisia");
mapexplr.MapProvider = GMapProviders.BingMap;
mapexplr.MinZoom = 3;
mapexplr.MaxZoom = 17;
mapexplr.Zoom = 5;
mapexplr.Manager.Mode = AccessMode.ServerAndCache;
//ajout des overlay
overlayOne = new GMapOverlay(mapexplr, "OverlayOne");
//ajout de Markers
overlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(36.657403,10.327148)));
//ajout de overlay à la map
mapexplr.Overlays.Add(overlayOne);
}
}
}
The final result:
Love you tunisia !
I hope this tutorial was helpful, till the next time don't stop sharing
gmap.net is a great .net framework nonetheless it lacks of documentation.
So what I'm going to do is to show you how to refer gmap.net in your application and how to locate something in the world map.
So let's get started!
First of all we need to download the binary package which contains all the *.dll that we need.
http://greatmaps.codeplex.com/releases/view/20235#DownloadId=67818
extract the folder in a decent place, say for exemple c:\\projects\
we will need only 2 files:
GMap.NET.Core.dll
GMap.NET.WindowsForms.dll
Now we will add the GMap.NET.WindowsForms.dll to our Visual Studio IDE toolbox.
to do so go to tools-->choose toolbox items
before clicking brows, make sure you selected the ".NET Framework Components"
Select the Gmap.NET.WindowsForms.dll
click Open or "ouvrir" the click ok
now go to your toolbox (view-->toolbox) you should find a new control the "GmapControl".
Next step is even more simple :))
we need to add a reference to our new library in our projects so go to:
(view-->Solution explorer)
Select the GMap.NET.Core.dll click Ok
Note that the reference are being added to your projects reference,
we can now go back to the design and set our gmap control
Right click on the control and choose "propoerties"
In the properties windows set the Name to "mapexplr"
Finally we can start coding
Add these lines to the using lines
using GMap.NET.WindowsForms;
using GMap.NET;
using GMap.NET.MapProviders;
The Code
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
GMapOverlay overlayOne;
String contry;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void mapexplr_Load(object sender, EventArgs e)
{
//initialisation de notre map
mapexplr.SetCurrentPositionByKeywords("Tunisia");
mapexplr.MapProvider = GMapProviders.BingMap;
mapexplr.MinZoom = 3;
mapexplr.MaxZoom = 17;
mapexplr.Zoom = 5;
mapexplr.Manager.Mode = AccessMode.ServerAndCache;
//ajout des overlay
overlayOne = new GMapOverlay(mapexplr, "OverlayOne");
//ajout de Markers
overlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(36.657403,10.327148)));
//ajout de overlay à la map
mapexplr.Overlays.Add(overlayOne);
}
}
}
The final result:
Love you tunisia !
I hope this tutorial was helpful, till the next time don't stop sharing
thanks , but how can I change the image of the marker ?!
RépondreSupprimerjust from here,
RépondreSupprimeroverlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(36.657403,10.327148)));
change GMapMarkerGoogleGreen with what you desire
why there is one warning when i run this program
RépondreSupprimeris says that contry never been used... please help me
Is there a way how to add a custom marker please?
RépondreSupprimerAbu Muslim Al-Amiri: what's your contry?
RépondreSupprimerMay be by creating a similar class to GmapMarkerGoogleGreen or modifying its code. Sorry I didn't try that before :(
RépondreSupprimerHi, How can I change the type of map?
RépondreSupprimerChange this line ,
Supprimermapexplr.MapProvider = GMapProviders. ;
choose the one you like
How can i display a map with specified boundaries. What i mean is i would like to display a map in between two points(corners)
RépondreSupprimerI don't know
SupprimerThanx a lot!
RépondreSupprimeryou are welcome
SupprimerSalam Mazen ,
RépondreSupprimerAs a young student I need your help in somthing ! Please help me ..
I want to implement Gmap in an application that will run on tablett win8
is it possible to programme a fonction that will return the current user position and when he moves it always keep updated? like a True gps software? any idea
Thank you
Hello,
RépondreSupprimerI'm really sorry, I don't have any experience with mobile developing.
Ce commentaire a été supprimé par l'auteur.
RépondreSupprimerMazen, this document is very useful for me. Also your presentation is simple, thank you for this.
RépondreSupprimerYou are welcom my dear
Supprimerhow can add multiple markers from datagridview in c# i have 1000 lat longs is it possibel to add it in gmap.net
RépondreSupprimerif (comboBox5.SelectedIndex == 0)//(REGION 1)
RépondreSupprimer{
gMapControl1.MaxZoom = 11;
gMapControl1.MinZoom = 1;
gMapControl1.Zoom = 2;
String Query = " SELECT top 10 Latitude,Longitude FROM [ICPS].[dbo].[Sheet3_kir] ";
SqlCommand cmdDatabase = new SqlCommand(Query, conDatabase);
//SqlDataReader myReader;
gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
GMapOverlay markersOverlay = new GMapOverlay("VCS MAP");
gMapControl1.Overlays.Add(markersOverlay);
for (int i = 0; i <= dataGridView1.Rows.Count; i++)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
var Latitude = float.Parse(dataGridView1.Columns[1]);
var Longitude = float.Parse(dataGridView1.Columns[2]);
gMapControl1.Position = new PointLatLng(Latitude, Longitude);
GMarkerGoogle m = new GMarkerGoogle(gMapControl1.Position, GMarkerGoogleType.green_pushpin);
//markersOverlay.Markers.Add(m);
}
Jazak allah keer brother. I love Tunisia.
RépondreSupprimerSalam from Oman
marhba bik
SupprimerI run the program but all maps cannot be loaded. What can I do?
RépondreSupprimerAre you connected to internet while you are running the map?
SupprimerHello I seem to be stuck with every tutorial i follow for GMap .NET.
RépondreSupprimerI am able to run the program but i dont see the map. I can drag the map but i see nothing.
Screenshot: http://i.imgur.com/tDrMGcn.png
This also happend when i tried this tutorial: http://www.websofia.com/2013/02/gmap-net-tutorial-maps-markers-and-polygons/
Any help would be great. I tried different mapproviders.