Using GMap - NET - Great Maps For Windows Forms & Presentation
Using GMap - NET - Great Maps For Windows Forms & Presentation
NET
SAIF KHAN
Saif Khan
{ I am Saif } "Knowledge is power, information is free, share it!"
26 Posts | 182 Comments
<< A simple DataSet XSD Viewer | Home | New DevExpress skin in the works >>
Here are a few things you need to understand when using the the control
ARCHIVES
• July 2012 (2) 1. What is the map control (GMapControl)? This is the control which renders the map.
• December 2011 (1)
• August 2011 (1) 2. What is an Overlay (GMapOverlay)? This is a layer on top of the map control. You can have several layers on top
• June 2011 (1) of a map, each layer representing, say, a route with stops, a list of stores etc.
• April 2011 (4)
• May 2010 (3) 3. What are Markers (GMapMarker)? These are the points on a layer, each representing a specific geo location
• April 2010 (1) (Lat,Lon) e.g. each drop point on a route.
• September 2009 (2)
4. What is a route (GMapRoute)? This is the path or direction between two or more points.
• July 2009 (1)
• March 2009 (2)
5. WTF are tiles? – well here is something to read…Bing Maps Tile System.
• February 2009 (4)
• January 2009 (2)
• December 2008 (2)
When you download the binary from codeplex (this post is on WinForms) you will find several files in the folder. You
only need the following
• [Link]
• [Link]
• x86 and x64 folders for the version at the time of writing this post. These folders include the
[Link] which is used for local caching of the data to reduce the request for map tiles.
Now, add the [Link] to your Visual Studio IDE toolbox. Create a new project [Link] or C#,
whatever your fancy and drag the GMapControl onto the form.
[Link]
With myMap
.SetCurrentPositionByKeywords("USA")
.MapType = [Link]
.MinZoom = 3
.MaxZoom = 17
.Zoom = 4
.[Link] = [Link]
End With
Note: You can set the default position of the map with (to list a few)
• SetCurrentPositionByKeywords(“country”) - USA
• SetCurrentPositionByKeywords(“state, country”) – Berlin, Germany
• SetCurrentPositionByKeywords(“province, country”) – Alberta, Canada
• Position = New PointLatLng(latitude,longitude) - New PointLatLng(54.6961334816182, 25.2985095977783)
basically you are creating a marker (GMapMarkerGoogleGreen) which takes an latitude and longitude as parameters.
Then I am adding that marker to the overlay (overlayOne).
In most cases you’ll need to add multiple markers to the overlay. You can do that with a loop e.g.
in the above code, I am iterating a list of customers, creating a new marker and adding it to the overlay.
Note: It is recommended that you have your points (address) geocoded first to get better performance. it makes no
sense having several hundred addresses geocoded on the fly each time you load your map if you are dealing with a
large list. Some service like google, have rate limits as to how many geocode query you can send to their servers in a
given day.
[Link](overlayOne)
• Removing/Hiding overlays
• Changing the Markers
• Adding labels
• Caching
• Routing
Dear Saif,
Your tutorial is very good although I work in C#. I am having trouble understanding of the [Link]
Control. although I can see a map in my form but I cannot position it to india. Also because of lack
of proper documentation it is not easy.
thanx
saurabh
Left by saurabh gupta on Sep 14, 2011 10:02 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Dear,
I got the zoom part finally. Can you tell me where to get the source code for the [Link] as i tried
downloading their examples none of them are working in my vs2010. Also i tried to download
through tortise but was unable to do so as it does not download and shows me error. Can you guide
me towards a working source code.
regds
saurabh
Left by saurabh on Sep 27, 2011 7:13 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
[Link]
p.s. all demos are working perfectly, thx Saif for examples
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login [Link]
# re: Using [Link] – Great Maps for Windows Forms & Presentation
# re: Using [Link] – Great Maps for Windows Forms & Presentation
can you share Windows form code with markers kindly share
Left by Hussain Munaf on Dec 10, 2011 8:34 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
!!!
Thanks
Left by logicchild on Jan 15, 2012 11:31 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Where is MapType ??
Left by Carlos A. on Feb 18, 2012 6:52 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
dear Saif,
I'm currently working desktop app using google map. Your tutorial's very helpful but i can't drag it.
Can you help me and share more examples pls pls...
Left by ENKHEE on Feb 27, 2012 2:42 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
hi.
same logicchild, .maptype not found...
T.Y.
Left by Giulio on Feb 29, 2012 2:11 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Anyone know if this control has any built-in methods for determining if a PointLatLng falls within a
GMapPolygon?
Left by Steve on Mar 07, 2012 9:23 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
/// <summary>
/// Determines if a Point is inside a polygon.
/// </summary>
/// <returns>Return True if the point is inside Polygon.</returns>
public static bool IsInsidePolygon(PointF[] polygon, PointF point)
{
using (GraphicsPath gp = new GraphicsPath())
{
[Link](polygon);
return [Link](point.X, point.Y);
}
}
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hi
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hello, My Name is Santiago! I m From Argentine! Excuise Me...Do you have de Code? I don under
stand the inicialization....un WinForm!
Thank!
Left by Santiago on May 15, 2012 8:47 AM
hello every body. please exuse me becose i cnow that my englich is so bed :(
I do it and i can calculate distance but routes are not visible on my map.
this is my C# code:
#region il y a des routes
IEnumerable<XElement> RoutesRq = from xElement in [Link]("Routelect
xElement;
bool HasRouts = false;
if ([Link]() > 0)
{
HasRouts = true;
int i = 1;
foreach (XElement route in RoutesRq)
{
List<PointLatLng> points = new List<PointLatLng>();
# re: Using [Link] – Great Maps for Windows Forms & Presentation
# re: Using [Link] – Great Maps for Windows Forms & Presentation
There is no .maptype in the latest releases. How do you set the map provider? I have tried
[Link]
everything I could find.
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login
# re: Using [Link] – Great Maps for Windows Forms & Presentation
# re: Using [Link] – Great Maps for Windows Forms & Presentation
I just started looking at this two days ago so my info is AFAIK based but after a bit of experimenting
I got the following to work.
I am using Visual Basic.
Replace XLAT and XLON with whatever coordinates you want
After adding references to the project try...
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link]
[Link](overlayOne)
End Sub
End Class
Left by Jerry on Jul 19, 2012 8:57 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Anyone knows how to show a custom info window (with tabs or something like you can do on a web
application) when clicking a marker using this control ??
Left by will on Sep 03, 2012 10:08 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
hi
thanks for ur tutorial but i have a problem with the maptype
Left by ahmed on Nov 14, 2012 1:43 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
i am very new in mapping pls explain further.
[Link]
Thanks
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login
# re: Using [Link] – Great Maps for Windows Forms & Presentation
hello,
Best Regards,
Marco Gaspar
Left by Marco Gaspar on Nov 23, 2012 7:52 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Great !
Can you share your code, thank you very much !
Left by Tuyen on Nov 23, 2012 4:24 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
[Link](New [Link](New
[Link](51.2961334816182, 7.0985095977783)))
[Link](overlayOne)
End Sub
Greets Lotto
Left by Lotto on Dec 09, 2012 11:36 PM
Hi lu,
[Link] = pnt
You can store the actual position of the map into a point:
pnt = [Link]
You can move around a map by moving the position. The following code moves the position of the
map to the right (east).
[Link]()
i hope it helps
greets Lotto
Left by Lotto on Dec 10, 2012 4:00 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
thanks in advance
Left by Mostafa Atef on Jan 12, 2013 4:36 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hi anyone know how to return the Lat and Long value when user clicking on the map? Preferably
using C#.
Left by Denny on Jan 15, 2013 1:47 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Anyone know how to get Long and Lat value when user clicking on the map? Using C# or VB is ok.
Left by Denny on Jan 15, 2013 1:53 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
i can drag map and also can add markers in it .... but here is my problem
..........................................................................................................
i have added more than 10 markers
&
also added their click event .....
but i am failed to judge that which marker (region) is clicked from 10 markers .....
i think it is possible by getting the latitude and langitude or by adding unique label in every
label.....please help how to get langitude and latitude of a marker
or
add unique label in a marker and how to read this marker
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hello Saif, I need to use the control to display a map using a shape file and integarte with my
desktop application to custom visualize spatially data from sql [Link] know i want with show
all mapping elements in my print lik Title, Legend and the different [Link] you tell a good
guide to accomplish [Link] share code [Link] you.
Left by Jonas on Mar 29, 2013 11:37 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
// In MainMap setup...
[Link] += new MouseEventHandler(MainMap_MouseDoubleClick);
[Link]
...
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login
Paul T.
Left by Paul T. on Jun 07, 2013 5:16 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
I'm struggling with removing overlays and I noticed you will be covering this in an upcoming blog. Do
you have a sense of when that might be? Is there a method for clearing the map with a button click
event?
Left by Jcarter on Jun 12, 2013 5:14 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Adding multiple markers from datagridview. I have a sql table which has 1000 latitudes, long values
I want all of them to display on the mapcontrol. can I do them on gmap i tried several ways but i cant
do it.
if ([Link] == 0)//(REGION 1)
{
String Query = " SELECT top 1000 Latitude,Longitude FROM [ICPS].[dbo].[Sheet3_kir] ";
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hey nice tutorial ...... i successfully added the markers and stuff .. but there's one problem .... it
always points d marker at the centre and then when i zoom in or out it show the actual position
Left by Raymond on Jul 27, 2013 12:21 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Dear Sir .
[Link]
I developed a test program in [Link] 2010 and using the last [Link]'ssion.
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login
I inicialice the map with a position .OK. But I have this problem : I am able to add only a mark .
This is the code
Dim o1 As New [Link]("o1
[Link](New [Link](New [Link](27.8, -15.39),
[Link]))
[Link](New [Link](New [Link](27.91248, -15.4117),
[Link]))
[Link](o1)
It only show 1 mark .
Why?
Thanks in advance
Left by santiago on Aug 30, 2013 4:28 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
# re: Using [Link] – Great Maps for Windows Forms & Presentation
I have found that the .Position sets the 0,0 position of the map control to the provided lat long X,Y
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Saif ---
Since you've written this, it looks like [Link] has gotten deprecated (apparently
replaced by [Link]).
m_wGmap.MapProvider = [Link];
Thanks again for your community spirit, and a great, concise intro!
-- Carl
Left by Carl Niedner on Oct 17, 2013 9:43 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Khan Saab,
how ru? I m having a problem with my sample application of GPS travel map, when I run it shows
me error (Webserver not found" in blue screen instead of showing map. I an actually not able to
understand where is gone wrong with my code,,
# re: Using [Link] – Great Maps for Windows Forms & Presentation
great work!
can i have a source code of your [Link]?
[Link]
it will be of great help to my thesis study..thank you
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hi guy! I have project Using GPS device to confirm location. So, I don't know how to use function
geocoding and Reverse ò Google map
So need your help?
Thank's
Left by Pham Tuan Anh on Apr 08, 2014 6:13 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
hi. please help me. I am new in map programming. I download greatmap samples. I downloaded
tiles with help greatmap. I publish this greatmap presentation samples to iis. But i dont show my
downloaded map in other pc. I need publish this samples to iis. Access them from another
computers which havent internet access as mapserver. How i do it. please help
Left by Kamran on May 26, 2014 1:12 AM
# Removing/Hiding overlays
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Thanks alot for your tutorial it was really good and helpfull,Can you please tell me that is it we get
UTC offset(TimeZones) of particular point by giving its Lat and log.
Left by Ravi on Jul 22, 2014 5:40 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
I am having trouble getting a Google map to display using VB 2010. The following code was
adapted from several different pages. The problem is that no map is displayed, just a blank screen
with the Google text at the bottom. I imported [Link] and [Link]. Mymap
is the name of my GMap control on the form.
[Link] = [Link]
[Link] = [Link]
[Link]("Maputo, Mozambique")
[Link](r)
[Link](routesOverlay)
End Sub
Is this a known issue? How do I resolve this? Could it be a firwall issue or a missing entry in a Hosts
file?
Many thanks
Len
Left by Len on Aug 22, 2014 3:51 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Hello,
It was a great tutorial for the beginners like me. I have one question.. is there any way to use GMap
in web application ([Link])... ??
If so then can you provide or suggest me for a sample of that.. ??
Thank You.
Left by Rasoo on Dec 08, 2014 8:48 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
How can I use the Drag option with mouse left button click?
Left by Rasoo on Dec 08, 2014 9:19 PM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
But this is not working with wpf as it working in winforms, that doesn't support marker and polygon in
wpf..
Left by Prakash N on Jan 07, 2015 12:54 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
In google Map , I can See Some Image below the Google map from show image Option. how i can
get It in My Application. I am working On C# windwos Application
Left by Sojeb on Mar 29, 2015 6:36 AM
# re: Using [Link] – Great Maps for Windows Forms & Presentation
Is it possible to move the map around using the left mouse button instead of the right one? I know
setting CanDragMap to true will allow it to be dragged with the right mouse button, but can this be
changed to the left one?
Left by goondoo27 on Apr 24, 2015 4:46 PM
Your comment:
Title:
re: Using [Link] – Great Maps for Windows Forms & Presentation
Name:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
Geeks with Blogs, the #1 blog community for IT Pros Start Your Blog Login [Link]
Verification:
Post Comment