| By Jeevan Murkoth | Article Rating: |
|
| October 15, 2008 10:30 AM EDT | Reads: |
266,542 |
Overlaying Markers and Pop-Up Windows
Another cool feature of Google Maps is the ability to display markers on the map and attach pop-up windows to these markers on the click event. It is possible to display formatted HTML containing links and images in these pop-up windows. Let us see how to do the same using the GMap ASP.NET control. Let's take the previous example and modify it to add two markers. One would be a plain marker and the other would have a pop-up window that would display some text. The GMap ASP.NET control has an overloaded method called OverlayMarker that takes the formatted HTML as a string parameter. If the overloaded method is called and some HTML is passed to the method, a click event is automatically passed to the marker and the info window is displayed. Listing 4 shows the code to overlay two markers and Figure 4 shows the output of the same.
Overlaying Custom Markers
Google gives us the flexibility to replace their standard marker icon with any custom icon that we specify. The same functionality is provided by the GMap ASP.NET control. In order to do so, we need to define a GIcon class with at least the following properties:
- URL of the image that would represent the GIcon
- URL of the shadow image
- Size of the image
- Size of the shadow
- The point at which the icon is to be anchored to the icon
In case info windows are used, it is also necessary to specify the point where the info window is to be anchored to the map. For this example we will be borrowing the icons from the Google Ride Finder application. Let's take the same two points that we used in the marker example and replace the standard marker icons with these custom icons. The code in Listing 5 is same as that of Listing 4, except for the use of custom icons. Figure 5 shows the output.
Overlaying Lines
In this section we will see how to overlay a line on a Google Map. Lines can be overlaid on maps to denote routes, boundaries, or some other specific purpose a developer may deem necessary. As in the Google Maps API, the GMap ASP.NET control also allows overlay of lines. In the GMap control, the GLine class represents a line and takes a collection of GPoints to plot a line through them. It is also possible to set the color, width, and opacity of the line. While the Google Maps API requires color to be passed in as a Hex value, the GMap control takes in a System.Drawing.Color structure, thereby making it easier to set the color by name. Listing 6 shows the code and Figure 6 shows the rendering.
Using Multiple Google Map Controls in a Page
So far in all of the examples, we have dealt with one instance of the control in a page. It is possible to have any number of GMap controls in a single page and have granular control over each one of them. In this example, we have four instances of the control and will center and zoom them on four different cities. Listing 7 shows the code and Figure 7 shows the output in the browser. It is possible to have markers or lines on any of these controls.
Binding Data to the Control
The GMap ASP.NET control supports data binding and it is possible to bind it to any data source that implements the IEnumerable interface, hence it can bind to most of the commonly used sources such as data tables, datasets, and collections. As of now the control only supports overlaying of standard markers via data binding. The control exposes the following properties that need to be set before data binding:
- MarkerLatitudeField: Property used to specify which field from the data source will bind to the latitude field of each marker in the control
- MarkerLongitudeField: Property used to specify which field from the data source will bind to the longitude field of each marker in the control
- MarkerText: Property used to specify which field from the data source will bind to the Text field of each marker in the control (this is optional)
- DataSource: Property used to set the source of data
In this example we will first populate a table with a point and then bind it to the GMap control. Listing 8 shows the code involved in the example and Figure 8 shows the output.
Conclusion
The Google Maps API is very versatile. I hope this control will make it easier for .NET developers to harness the potential of this API.
References
- Google Maps API documentation: www.google.com/apis/maps/documentation/
- Google Maps news groups: www.google.com/apis/maps/documentation/
- Onion, F. (2003). Essential ASP.NET (Custom Controls). Addison-Wesley Professional.
Published October 15, 2008 Reads 266,542
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jeevan Murkoth
Jeevan Murkoth is a Microsoft Certified Solutions Developer (MCSD) in .NET (Early Achiever) and a Microsoft Certified Application Developer (MCAD) in .NET. He currently consults for Tennessee Valley Authority and lives in Chattanooga, TN. He has an MS in Management Information Systems from Texas Tech University.
![]() |
stuartlodge 01/08/09 08:00:49 PM EST | |||
Is anyone else developing this control forwards? Can I update the control and republish it? (with credits obviously). e.g. I've just spent a couple of hours updating bits to GMap2 so as to use GLatLngBounds - http://slodge.blogspot.com/2009/01/adding-bounding-box-to-google-maps-in... |
||||
![]() |
punkbd 12/15/08 10:45:53 AM EST | |||
Where is the control? Very unfriendly site. On 'Your Feedback' what's the point of have 'read more & respond' link if it does nothing. Really stupid. |
||||
![]() |
stuartlodge 12/09/08 04:41:47 AM EST | |||
Zachary - if you click on any of the code sample page links then there are additional download options at the top of the code sample pages - the sample code download includes the control. One word of warning - the zip file contains lots of Apple Mac (Vista unfriendly) thumbnail files. |
||||
![]() |
stuartlodge 12/09/08 04:39:57 AM EST | |||
Thanks for this excellent article and control. I've put the code for a fixed JScriptGenerator.cs on my blog at http://slodge.blogspot.com/2008/12/jscriptgeneratorcs-with-fixes-for.html - this fixes the addOverlays problems and the GMAP_TYPE problems. |
||||
![]() |
zwheeler 12/08/08 04:55:25 PM EST | |||
where is the gmap control.so i can download it |
||||
![]() |
erom 11/19/08 05:40:46 AM EST | |||
I downloaded and tried to run the SampleSolution through Visual Studio. Every time that I am running the pages (.aspx) which exist in the SampleSolution I am getting the same errror 'G_MAP_TYPE' is undefined. Can someone suggest a possible solution? |
||||
![]() |
sahil_mohali 10/15/08 07:13:12 AM EDT | |||
asdsdfv fdfd |
||||
![]() |
sahil_mohali 10/14/08 11:19:55 AM EDT | |||
How to use onmouseover on marker with c# code, by default when u click on marker then info window open, i want this with onmouseover????????? |
||||
![]() |
sahil_mohali 10/14/08 07:57:47 AM EDT | |||
help |
||||
![]() |
sahil_mohali 10/14/08 05:26:08 AM EDT | |||
any one please help regarding this? |
||||
![]() |
sahil_mohali 10/13/08 02:57:44 PM EDT | |||
How to use onmouseover on marker with c# code, by default when u click on marker then info window open, i want this with onmouseover????????? |
||||
![]() |
webpossible 09/27/08 04:34:04 PM EDT | |||
ah just found the source, you need to click on list 1 from the main article and then click on the first link in this page. easy when you know where to look. |
||||
![]() |
webpossible 09/27/08 03:03:20 PM EDT | |||
where can I download this marvelous Google Maps ASP.NET Control (GMAP Control) from ? I cant seem to find a link for this anywhere. Thanks for your help and for writing this excellent article. |
||||
![]() |
Noble 07/25/08 01:45:27 AM EDT | |||
I got the same java script error in JScriptGenerator.cs with Can You Please put your full JScriptGenerator.cs |
||||
![]() |
Sajid Mushtaq 04/09/08 07:42:55 AM EDT | |||
i cant find a link to download the source code and the control. Please help. Regards, |
||||
![]() |
Shabdar 03/25/08 11:53:05 AM EDT | |||
I have created similar control. It works with latest versions of Google Maps API. Here is the link, http://www.shabdar.org/google-maps-user-control-for-ASP-Net-part1.html |
||||
![]() |
Ghata 03/24/08 10:51:31 AM EDT | |||
This one works with GMAP2 http://www.shabdar.org/google-maps-user-control-for-ASP-Net-part1.html |
||||
![]() |
Balvinder 01/10/08 12:44:05 AM EST | |||
I have downloaded GMap control and sample applications. Following code does not works. Please, tellme what is going wrong ? Suggest any modifications in code. GMapControl1.Width=400; |
||||
![]() |
Sai 12/14/07 05:24:08 AM EST | |||
There is a change in google api and this shows a javascript error. So please remove "this.reOrderOverlays();" from GenerateNewOverLayFunction() in JScriptGenerator.cs file. You may find more info on this at http://groups.google.com/group/Google-Maps-API/browse_thread/thread/96fe... |
||||
![]() |
baybay 12/03/07 10:25:36 PM EST | |||
This article is horrible. Very generic. Don't waste your time. |
||||
![]() |
fabrice 11/19/07 05:27:23 AM EST | |||
How do you deal with events ? |
||||
![]() |
Derek 11/18/07 10:18:07 PM EST | |||
Here's the fix for the marker issue that everyone seems to still be having a problem with. In JScriptGenerator.cs replace with the overlays.push is what looks to be causing the problem. After making this fix, I can lay markers on the map. Cheers |
||||
![]() |
Josh 10/01/07 11:54:26 AM EDT | |||
Patrick - Here is good easy to use control with full functionality. I did have a problem in deployment with the key, so I would recommend testing it on your server before you do a lot of development. |
||||
![]() |
Patrick 09/30/07 02:49:43 PM EDT | |||
Hi Jeevan, |
||||
![]() |
Jeevan 08/27/07 05:04:32 PM EDT | |||
Hi Josh, Thanks |
||||
![]() |
Josh 08/27/07 04:34:59 PM EDT | |||
Great, but I kind of need to display markers. Its actually the key part of displaying the map. After playing around with this a while, markers or custom markers will not display. Several others had the same problem. Any ideas, or just skirting the issue? |
||||
![]() |
Eric 08/13/07 01:31:52 PM EDT | |||
Where do I go to download the GMap Control. I was lost trying to follow the step. |
||||
![]() |
san 08/02/07 08:20:00 AM EDT | |||
I have downloaded GMap control and sample applications. Following code does not works. Please, tellme what is going wrong ? Suggest any modifications in code. GMapControl1.Width=400; |
||||
![]() |
Priya 07/19/07 01:02:11 PM EDT | |||
I am getting an error in reOrderOverlays(). It says object dosen't support this property. I am getting a java script error. Is there a fix for this? Please let me know. |
||||
![]() |
Rhys 07/10/07 04:31:10 AM EDT | |||
This looks awfully plaguerised from an article at another site... Naughty, naughty, very naughty! |
||||
![]() |
Troy Johnson 06/08/07 10:52:38 AM EDT | |||
Anyone know if this is or will soon be updated to use GMap2? |
||||
![]() |
Niketa 06/05/07 11:32:18 PM EDT | |||
this code is working fine but i am not able to draw lines and could not use marker. please help me in this. i had to commen reOrderOverlays() funstion call as my code was not working . please suggest me how can i resolve this. Thanks a lot. |
||||
![]() |
Ridhi 06/05/07 11:24:10 PM EDT | |||
Thanks Jeevan , but i am not able to see marker and polylines or lines using this tool , please help me in this . i have tried simple code . i had to comment reOrderOverlays() to make this tool working. Please suggest the way to resolve it or problem. |
||||
![]() |
Tom 04/23/07 06:57:02 PM EDT | |||
Thanks for this tool Jeevan, unfortunately I can't seem to get any markers to display (have tried the sample code as well as different browsers). No errors, just no markers! I noticed some others had this issue. Do you have any idea what may be causing this as I'd love to be able to use it properly! |
||||
![]() |
Gordon Hooton 03/29/07 11:01:25 PM EDT | |||
Excellent article, is thee any way to extend the properties of the MapControl to return the current latitude, longtitude of the displayed map centre and the zoom level ? I know these are available in Google Maps Javascript. |
||||
![]() |
Mohsen Pourett 02/16/07 01:14:13 PM EST | |||
I have downloaded the code and sample project. I have converted the code to vb.net and have been able to display the basic map properly (MapControl.dll is dated (10/9/2005). However, I have not yet to succeed in getting markers and info popups to show. The version downladed also does not have any databinding methods or attributes! any suggestions /help will be appreciated. Unfortunately, I can not provide a URL to the project since it is on Intranet servers. The code for the page with difficulty is as follows: 1. codeBehind: Imports System Public Class BasicMap #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. End Sub 'NOTE: The following placeholder declaration is required by the Web Form Designer. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Class 2- html: <%@ Register TagPrefix="cc1" Namespace="MapControl" Assembly="MapControl" %> BasicMap v\:* {BEHAVIOR: url(#default#VML)} 3- Page error: Line: 32 |
||||
![]() |
Jimi Schacht 02/08/07 04:10:01 PM EST | |||
Awsome! At last a .Net wrapper for the API that actually works!... ...But, for some reason i cannot get markers or lines to display. I use your example code and can't get the to show up with or without messing with the code. Is issue? |
||||
![]() |
Jimi Schacht 02/08/07 04:08:54 PM EST | |||
Awsome! At last a .Net wrapper for the API that actually works!... ...But, for some reason i cannot get markers or lines to display. I use your example code and can't get the to show up with or without messing with the code. Is issue? |
||||
![]() |
Joginder 11/05/06 01:46:25 PM EST | |||
Hi, I am very much interested in the source code that shows how to handle click events on the map using Jeevan's control. If the project is in ASP.NET developed using VB.NET would be even better. Regards, |
||||
![]() |
Jay Scott 09/19/06 08:14:30 AM EDT | |||
Thank you Jeevan. Is there a way of outlining an entire area? For instance a map of the US would have each of the states outlined, clicking on one would zoom in and show different points within the state. |
||||
![]() |
Jeevan 09/19/06 07:44:26 AM EDT | |||
Hi Jay , |
||||
![]() |
Jay Scott 09/18/06 10:52:35 AM EDT | |||
Your article is great. What I could not find was a way to download the control. |
||||
![]() |
SYS-CON Belgium News Desk 09/14/06 03:36:38 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
SYS-CON Brazil News Desk 09/14/06 03:12:23 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
SYS-CON Australia News Desk 09/14/06 01:53:52 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
Enterprise Open Source News Desk 09/14/06 01:09:42 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
SYS-CON Brazil News Desk 09/13/06 05:30:17 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
n d 09/13/06 03:14:52 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
n d 09/12/06 07:00:05 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
![]() |
n d 09/12/06 06:49:42 PM EDT | |||
I am sure that most of you have heard about or have had a chance to use Google Maps. It's a great service and I was really impressed by the responsiveness of the application and the ease with which users could drag and zoom maps from a Web browser. It has in many ways heralded the arrival of AJAX (Asynchronous JavaScript and XML), which I am sure will revitalize Web development in the days to come. |
||||
- Microsoft’s First Step Toward Cloud Computing
- Adobe Flex Developer Earns $100K in New York City
- Jill T. Singer of CIA to Present at Cloud Computing Expo on November 2
- Visual Studio 2010 Is Cloud Friendly
- SplendidCRM for Microsoft Windows Azure
- Microsoft Falls Off Cliff, Keeps on Ticking
- Microsoft to Data-Mine Facebook & Twitter
- Amazon RDS vs. SQL Azure
- Azure Gets its First Commercial ERP App
- Qt DevDays 2009 - Munich
- Installing Geneva Beta 2 on Windows 7
- Binary Serialization and Azure Web Applications
- Yahoo! to Present at 4th International Cloud Computing Expo
- Microsoft’s First Step Toward Cloud Computing
- Social Media on Ulitzer - Strategy Nets New AUM for RIA
- EC Wrong, Wrong, Wrong – and Sloppy to Boot: Intel
- Adobe Flex Developer Earns $100K in New York City
- This Bing Thing Is Working
- Jill T. Singer of CIA to Present at Cloud Computing Expo on November 2
- Visual Studio 2010 Is Cloud Friendly
- SplendidCRM for Microsoft Windows Azure
- Azure on Ulitzer - Microsoft’s Cloud Builder Floats to Cisco: Report
- Governmental Cloud Interoperability on The Microsoft Cloud
- Microsoft Falls Off Cliff, Keeps on Ticking
- Where Are RIA Technologies Headed in 2008?
- The Top 250 Players in the Cloud Computing Ecosystem
- Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight
- Silverlight 2 - Adobe Flex Killer Is on Its Way!
- Building Great AJAX Applications Using ASP.NET
- Spice Up User Experience with Silverlight
- Is the Silverlight Adoption Rate Artificially Inflated?
- Kaazing Announces Support for Silverlight
- Will Google's Android Sink or Swim?
- VS 2008 Builds AJAX-based Web Apps
- Rich Content Rotator for ASP.NET
- Getting Started with Silverlight: Zero to Hero




































